Change in openvpn[master]: Add support to "ovpn" aka "in upstream kernel"
A message that is not in the archive (sent off-list or not yet received): gerrit.1744809221000.I009f4e7ad38636f1c0b78d267561194c2bb4c051@...2715...
Attention is currently required from: flichtenheld, plaisthos.
Hello plaisthos, flichtenheld,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/941?usp=email
to review the following change.
Change subject: Add support to "ovpn" aka "in upstream kernel"
......................................................................
Add support to "ovpn" aka "in upstream kernel"
Introduce new userspace APIs to communicate with "ovpn".
---
M src/openvpn/dco_linux.c
M src/openvpn/dco_linux.h
M src/openvpn/networking_sitnl.c
M src/openvpn/ovpn_dco_linux.h
4 files changed, 257 insertions(+), 329 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/41/941/1
src/openvpn/dco_linux.c +164 -108
@@ -96,7 +96,7 @@ }set_cloexec (nl_socket_get_fd (nl_sock)); - ret =genl_ctrl_resolve (nl_sock,OVPN_NL_NAME ); + ret =genl_ctrl_resolve (nl_sock,OVPN_FAMILY_NAME );if (ret <0 ) { msg(msglevel, "Cannot find ovpn_dco netlink component: %s",
@@ -109,7 +109,7 @@ }static struct nl_msg * -ovpn_dco_nlmsg_create (dco_context_t *dco,enum ovpn_nl_commands cmd) +ovpn_dco_nlmsg_create (dco_context_t *dco,int cmd) {struct nl_msg *nl_msg =nlmsg_alloc ();if (!nl_msg)
@@ -119,7 +119,7 @@ }genlmsg_put (nl_msg,0 ,0 , dco->ovpn_dco_id,0 ,0 , cmd,0 ); -NLA_PUT_U32 (nl_msg,OVPN_ATTR_IFINDEX , dco->ifindex); +NLA_PUT_U32 (nl_msg,OVPN_A_IFINDEX , dco->ifindex);return nl_msg; nla_put_failure:
@@ -231,20 +231,31 @@msg (D_DCO_DEBUG ,"%s: peer-id %d, fd %d, remote addr: %s" , __func__, peerid, sd, remotestr); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_NEW_PEER ); -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_NEW_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_NEW ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_PEER_ID , peerid); -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_SOCKET , sd); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_SOCKET , sd);/* Set the remote endpoint if defined (for UDP) */ if (remoteaddr) { remoteaddr =mapped_v4_to_v6 (remoteaddr, &gc); -int alen =af_addr_size (remoteaddr->sa_family); -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_SOCKADDR_REMOTE , alen, remoteaddr); +if (remoteaddr->sa_family ==AF_INET ) + { +NLA_PUT (nl_msg,OVPN_A_PEER_REMOTE_IPV4 ,sizeof (struct in_addr ), + &((struct sockaddr_in *)remoteaddr)->sin_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_REMOTE_PORT , ((struct sockaddr_in *)remoteaddr)->sin_port); + } +else if (remoteaddr->sa_family ==AF_INET6 ) + { +NLA_PUT (nl_msg,OVPN_A_PEER_REMOTE_IPV6 ,sizeof (struct in6_addr ), + &((struct sockaddr_in6 *)remoteaddr)->sin6_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_REMOTE_PORT , ((struct sockaddr_in6 *)remoteaddr)->sin6_port); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_REMOTE_IPV6_SCOPE_ID , ((struct sockaddr_in6 *)remoteaddr)->sin6_scope_id); + } }if (localaddr)
@@ -252,24 +263,26 @@ localaddr =mapped_v4_to_v6 (localaddr, &gc);if (localaddr->sa_family ==AF_INET ) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_LOCAL_IP ,sizeof (struct in_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_LOCAL_IPV4 ,sizeof (struct in_addr ), &((struct sockaddr_in *)localaddr)->sin_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_LOCAL_PORT , ((struct sockaddr_in *)localaddr)->sin_port); }else if (localaddr->sa_family ==AF_INET6 ) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_LOCAL_IP ,sizeof (struct in6_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_LOCAL_IPV6 ,sizeof (struct in6_addr ), &((struct sockaddr_in6 *)localaddr)->sin6_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_LOCAL_PORT , ((struct sockaddr_in6 *)localaddr)->sin6_port); } }/* Set the primary VPN IP addresses of the peer */ if (vpn_ipv4) { -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_IPV4 , vpn_ipv4->s_addr); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_VPN_IPV4 , vpn_ipv4->s_addr); }if (vpn_ipv6) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_IPV6 ,sizeof (struct in6_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_VPN_IPV6 ,sizeof (struct in6_addr ), vpn_ipv6); }nla_nest_end (nl_msg, attr);
@@ -481,7 +494,7 @@msg (D_DCO_DEBUG ,"%s: %s" , __func__, dev);ASSERT (tt->type ==DEV_TYPE_TUN ); -int ret =net_iface_new (ctx, dev,"ovpn-dco" , &tt->dco); +int ret =net_iface_new (ctx, dev,OVPN_FAMILY_NAME , &tt->dco);if (ret <0 ) {msg (D_DCO_DEBUG ,"Cannot create DCO interface %s: %d" , dev, ret);
@@ -515,22 +528,23 @@ {msg (D_DCO_DEBUG ,"%s: peer-id %d" , __func__, peerid); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_SWAP_KEYS ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_SWAP );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_SWAP_KEYS ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_KEYCONF );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_SWAP_KEYS_ATTR_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__); - -nla_put_failure:nlmsg_free (nl_msg);return ret; +nla_put_failure: +nlmsg_free (nl_msg); +return -1 ; }
@@ -539,21 +553,23 @@ {msg (D_DCO_DEBUG ,"%s: peer-id %d" , __func__, peerid); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_DEL_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_DEL );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_DEL_PEER ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_DEL_PEER_ATTR_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__); - +nlmsg_free (nl_msg); +return ret; nla_put_failure:nlmsg_free (nl_msg); + ret =-1 ;return ret; }
@@ -562,19 +578,20 @@ dco_del_key(dco_context_t *dco, unsigned int peerid, dco_key_slot_t slot) { +int ret = -EMSGSIZE ;msg (D_DCO_DEBUG ,"%s: peer-id %d, slot %d" , __func__, peerid, slot); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_DEL_KEY ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_DEL );if (!nl_msg) {return -ENOMEM ; } +struct nlattr *keyconf; -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_DEL_KEY ); -int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_DEL_KEY_ATTR_PEER_ID , peerid); -NLA_PUT_U8 (nl_msg,OVPN_DEL_KEY_ATTR_KEY_SLOT , slot); -nla_nest_end (nl_msg, attr); + keyconf =nla_nest_start (nl_msg,OVPN_A_KEYCONF ); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_SLOT , slot); +nla_nest_end (nl_msg, keyconf); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -596,7 +613,7 @@const size_t key_len =cipher_kt_key_size (ciphername);const int nonce_tail_len =8 ; -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_NEW_KEY ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_NEW );if (!nl_msg) {return -ENOMEM ;
@@ -605,33 +622,35 @@dco_cipher_t dco_cipher =dco_get_cipher (ciphername);int ret = -EMSGSIZE ; -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_NEW_KEY ); -NLA_PUT_U32 (nl_msg,OVPN_NEW_KEY_ATTR_PEER_ID , peerid); -NLA_PUT_U8 (nl_msg,OVPN_NEW_KEY_ATTR_KEY_SLOT , slot); -NLA_PUT_U8 (nl_msg,OVPN_NEW_KEY_ATTR_KEY_ID , keyid); -NLA_PUT_U16 (nl_msg,OVPN_NEW_KEY_ATTR_CIPHER_ALG , dco_cipher); + +struct nlattr *key_conf =nla_nest_start (nl_msg,OVPN_A_KEYCONF ); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_SLOT , slot); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_KEY_ID , keyid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_CIPHER_ALG , dco_cipher);struct nlattr *key_enc =nla_nest_start (nl_msg, -OVPN_NEW_KEY_ATTR_ENCRYPT_KEY ); +OVPN_A_KEYCONF_ENCRYPT_DIR );if (dco_cipher !=OVPN_CIPHER_ALG_NONE ) { -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_CIPHER_KEY , key_len, encrypt_key); -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_NONCE_TAIL , nonce_tail_len, +NLA_PUT (nl_msg,OVPN_A_KEYDIR_CIPHER_KEY , key_len, encrypt_key); +NLA_PUT (nl_msg,OVPN_A_KEYDIR_NONCE_TAIL , nonce_tail_len, encrypt_iv); }nla_nest_end (nl_msg, key_enc);struct nlattr *key_dec =nla_nest_start (nl_msg, -OVPN_NEW_KEY_ATTR_DECRYPT_KEY ); +OVPN_A_KEYCONF_DECRYPT_DIR );if (dco_cipher !=OVPN_CIPHER_ALG_NONE ) { -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_CIPHER_KEY , key_len, decrypt_key); -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_NONCE_TAIL , nonce_tail_len, +NLA_PUT (nl_msg,OVPN_A_KEYDIR_CIPHER_KEY , key_len, decrypt_key); +NLA_PUT (nl_msg,OVPN_A_KEYDIR_NONCE_TAIL , nonce_tail_len, decrypt_iv); }nla_nest_end (nl_msg, key_dec); -nla_nest_end (nl_msg, attr); +nla_nest_end (nl_msg, key_conf); + ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -647,18 +666,18 @@msg (D_DCO_DEBUG ,"%s: peer-id %d, keepalive %d/%d, mss %d" , __func__, peerid, keepalive_interval, keepalive_timeout, mss); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_SET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_SET );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_SET_PEER ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_PEER_ID , peerid); -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_KEEPALIVE_INTERVAL , +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_KEEPALIVE_INTERVAL , keepalive_interval); -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_KEEPALIVE_TIMEOUT , +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_KEEPALIVE_TIMEOUT , keepalive_timeout);nla_nest_end (nl_msg, attr);
@@ -707,7 +726,7 @@ }if (strncmp (nla_data (tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME ]), -OVPN_NL_MULTICAST_GROUP_PEERS , +OVPN_MCGRP_PEERS ,nla_len (tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME ])) !=0 ) {continue ;
@@ -720,7 +739,7 @@ }/** * Lookup the multicast id for OpenVPN. This method and its help method currently -* hardcode the lookup to OVPN_NL_NAME and OVPN_NL_MULTICAST_GROUP_PEERS but +* hardcode the lookup to OVPN_FAMILY_NAME and OVPN_MCGRP_PEERS but * extended in the future if we need to lookup more than one mcast id. */ static int
@@ -741,7 +760,7 @@genlmsg_put (nl_msg,0 ,0 , ctrlid,0 ,0 ,CTRL_CMD_GETFAMILY ,0 );int ret = -EMSGSIZE ; -NLA_PUT_STRING (nl_msg,CTRL_ATTR_FAMILY_NAME ,OVPN_NL_NAME ); +NLA_PUT_STRING (nl_msg,CTRL_ATTR_FAMILY_NAME ,OVPN_FAMILY_NAME ); ret =ovpn_nl_msg_send (dco, nl_msg, mcast_family_handler, dco, __func__);
@@ -757,38 +776,38 @@dco_context_t *dco = arg;struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg)); -struct nlattr *attrs[OVPN_ATTR_MAX +1 ]; +struct nlattr *attrs[OVPN_A_PEER_MAX +1 ];struct nlmsghdr *nlh =nlmsg_hdr (msg);if (!genlmsg_valid_hdr (nlh,0 )) {msg (D_DCO ,"ovpn-dco: invalid header" ); -return NL_SKIP ; +return NL_STOP ; } -if (nla_parse (attrs,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +if (nla_parse (attrs,OVPN_A_PEER_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL )) {msg (D_DCO ,"received bogus data from ovpn-dco" ); -return NL_SKIP ; +return NL_STOP ; }/* we must know which interface this message is referring to in order to * avoid mixing messages for other instances */ -if (!attrs[OVPN_ATTR_IFINDEX ]) +if (!attrs[OVPN_A_IFINDEX ]) {msg (D_DCO ,"ovpn-dco: Received message without ifindex" ); -return NL_SKIP ; +return NL_STOP ; } -uint32_t ifindex =nla_get_u32 (attrs[OVPN_ATTR_IFINDEX ]); +uint32_t ifindex =nla_get_u32 (attrs[OVPN_A_IFINDEX ]);if (ifindex != dco->ifindex) {msg (D_DCO_DEBUG ,"ovpn-dco: ignoring message (type=%d) for foreign ifindex %d" , gnlh->cmd, ifindex); -return NL_SKIP ; +return NL_STOP ; }/* based on the message type, we parse the subobject contained in the
@@ -800,40 +819,77 @@*/ switch (gnlh->cmd) { -case OVPN_CMD_DEL_PEER : +case OVPN_CMD_PEER_DEL_NTF : { -if (!attrs[OVPN_ATTR_DEL_PEER ]) +if (!attrs[OVPN_A_PEER ]) { -msg (D_DCO ,"ovpn-dco: no attributes in OVPN_DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no attributes in OVPN_PEER_DEL message" ); +return NL_STOP ; } -struct nlattr *dp_attrs[OVPN_DEL_PEER_ATTR_MAX +1 ]; -if (nla_parse_nested (dp_attrs,OVPN_DEL_PEER_ATTR_MAX , - attrs[OVPN_ATTR_DEL_PEER ],NULL )) +struct nlattr *dp_attrs[OVPN_A_PEER_MAX +1 ]; +if (nla_parse_nested (dp_attrs,OVPN_A_PEER_MAX , + attrs[OVPN_A_PEER ],NULL )) { -msg (D_DCO ,"received bogus del peer packet data from ovpn-dco" ); -return NL_SKIP ; +msg (D_DCO ,"received bogus peer del packet data from ovpn-dco" ); +return NL_STOP ; } -if (!dp_attrs[OVPN_DEL_PEER_ATTR_REASON ]) +if (!dp_attrs[OVPN_A_PEER_DEL_REASON ]) { -msg (D_DCO ,"ovpn-dco: no reason in DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no reason in PEER_DEL message" ); +return NL_STOP ; } -if (!dp_attrs[OVPN_DEL_PEER_ATTR_PEER_ID ]) +if (!dp_attrs[OVPN_A_PEER_ID ]) { -msg (D_DCO ,"ovpn-dco: no peer-id in DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no peer-id in PEER_DEL message" ); +return NL_STOP ; } -int reason =nla_get_u8 (dp_attrs[OVPN_DEL_PEER_ATTR_REASON ]); -unsigned int peerid =nla_get_u32 (dp_attrs[OVPN_DEL_PEER_ATTR_PEER_ID ]); +int reason =nla_get_u32 (dp_attrs[OVPN_A_PEER_DEL_REASON ]); +unsigned int peerid =nla_get_u32 (dp_attrs[OVPN_A_PEER_ID ]); -msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_DEL_PEER, ifindex: %d, peer-id %d, reason: %d" , +msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_PEER_DEL, ifindex: %d, peer-id %d, reason: %d" , ifindex, peerid, reason); dco->dco_message_peer_id = peerid; dco->dco_del_peer_reason = reason; - dco->dco_message_type =OVPN_CMD_DEL_PEER ; + dco->dco_message_type =OVPN_CMD_PEER_DEL_NTF ; + +break ; + } + +case OVPN_CMD_KEY_SWAP_NTF : + { +if (!attrs[OVPN_A_KEYCONF ]) + { +msg (D_DCO ,"ovpn-dco: no attributes in OVPN_KEY_SWAP message" ); +return NL_STOP ; + } + +struct nlattr *dp_attrs[OVPN_A_KEYCONF_MAX +1 ]; +if (nla_parse_nested (dp_attrs,OVPN_A_KEYCONF_MAX , + attrs[OVPN_A_KEYCONF ],NULL )) + { +msg (D_DCO ,"received bogus swap key packet data from ovpn-dco" ); +return NL_STOP ; + } +if (!dp_attrs[OVPN_A_KEYCONF_PEER_ID ]) + { +msg (D_DCO ,"ovpn-dco: no peer-id in KEY_SWAP message" ); +return NL_STOP ; + } +if (!dp_attrs[OVPN_A_KEYCONF_KEY_ID ]) + { +msg (D_DCO ,"ovpn-dco: no key-id in KEY_SWAP message" ); +return NL_STOP ; + } +int key_id =nla_get_u16 (dp_attrs[OVPN_A_KEYCONF_KEY_ID ]); +unsigned int peer_id =nla_get_u32 (dp_attrs[OVPN_A_KEYCONF_PEER_ID ]); + +msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_KEY_SWAP, ifindex: %d, peer-id %d, key-id: %d" , + ifindex, peer_id, key_id); + dco->dco_message_peer_id = peer_id; + dco->dco_message_key_id = key_id; + dco->dco_message_type =OVPN_CMD_KEY_SWAP_NTF ;break ; }
@@ -841,7 +897,7 @@default :msg (D_DCO ,"ovpn-dco: received unknown command: %d" , gnlh->cmd); dco->dco_message_type =0 ; -return NL_SKIP ; +return NL_STOP ; }return NL_OK ;
@@ -859,9 +915,9 @@static void dco_update_peer_stat (struct context_2 *c2,struct nlattr *tb[],uint32_t id) { -if (tb[OVPN_GET_PEER_RESP_ATTR_LINK_RX_BYTES ]) +if (tb[OVPN_A_PEER_LINK_RX_BYTES ]) { - c2->dco_read_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_LINK_RX_BYTES ]); + c2->dco_read_bytes =nla_get_u64 (tb[OVPN_A_PEER_LINK_RX_BYTES ]);msg (D_DCO_DEBUG ,"%s / dco_read_bytes: " counter_format, __func__, c2->dco_read_bytes); }
@@ -871,9 +927,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_LINK_TX_BYTES ]) +if (tb[OVPN_A_PEER_LINK_TX_BYTES ]) { - c2->dco_write_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_LINK_TX_BYTES ]); + c2->dco_write_bytes =nla_get_u64 (tb[OVPN_A_PEER_LINK_TX_BYTES ]);msg (D_DCO_DEBUG ,"%s / dco_write_bytes: " counter_format, __func__, c2->dco_write_bytes); }
@@ -883,9 +939,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_VPN_RX_BYTES ]) +if (tb[OVPN_A_PEER_VPN_RX_BYTES ]) { - c2->tun_read_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_VPN_RX_BYTES ]); + c2->tun_read_bytes =nla_get_u64 (tb[OVPN_A_PEER_VPN_RX_BYTES ]);msg (D_DCO_DEBUG ,"%s / tun_read_bytes: " counter_format, __func__, c2->tun_read_bytes); }
@@ -895,9 +951,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_VPN_TX_BYTES ]) +if (tb[OVPN_A_PEER_VPN_TX_BYTES ]) { - c2->tun_write_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_VPN_TX_BYTES ]); + c2->tun_write_bytes =nla_get_u64 (tb[OVPN_A_PEER_VPN_TX_BYTES ]);msg (D_DCO_DEBUG ,"%s / tun_write_bytes: " counter_format, __func__, c2->tun_write_bytes); }
@@ -911,33 +967,33 @@int dco_parse_peer_multi (struct nl_msg *msg,void *arg) { -struct nlattr *tb[OVPN_ATTR_MAX +1 ]; +struct nlattr *tb[OVPN_A_PEER_MAX ];struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg));msg (D_DCO_DEBUG ,"%s: parsing message..." , __func__); -nla_parse (tb,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +nla_parse (tb,OVPN_A_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL ); -if (!tb[OVPN_ATTR_GET_PEER ]) +if (!tb[OVPN_A_PEER_ID ]) {return NL_SKIP ; } -struct nlattr *tb_peer[OVPN_GET_PEER_RESP_ATTR_MAX +1 ]; +struct nlattr *tb_peer[OVPN_A_PEER_MAX ]; -nla_parse (tb_peer,OVPN_GET_PEER_RESP_ATTR_MAX , -nla_data (tb[OVPN_ATTR_GET_PEER ]), -nla_len (tb[OVPN_ATTR_GET_PEER ]),NULL ); +nla_parse (tb_peer,OVPN_A_PEER_MAX , +nla_data (tb[OVPN_A_PEER_ID ]), +nla_len (tb[OVPN_A_PEER_ID ]),NULL ); -if (!tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]) +if (!tb_peer[OVPN_A_PEER_ID ]) {msg (M_WARN ,"%s: no peer-id provided in reply" , __func__);return NL_SKIP ; }struct multi_context *m = arg; -uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]); +uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_A_PEER_ID ]);if (peer_id >= m->max_clients || !m->instances[peer_id]) {
@@ -957,7 +1013,7 @@ {msg (D_DCO_DEBUG ,"%s" , __func__); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_GET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_GET );nlmsg_hdr (nl_msg)->nlmsg_flags |=NLM_F_DUMP ;
@@ -979,33 +1035,33 @@ dco_parse_peer(struct nl_msg *msg, void *arg) { struct context *c = arg; -struct nlattr *tb[OVPN_ATTR_MAX +1 ]; +struct nlattr *tb[OVPN_A_MAX ];struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg));msg (D_DCO_DEBUG ,"%s: parsing message..." , __func__); -nla_parse (tb,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +nla_parse (tb,OVPN_A_PEER_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL ); -if (!tb[OVPN_ATTR_GET_PEER ]) +if (!tb[OVPN_A_PEER_ID ]) {msg (D_DCO_DEBUG ,"%s: malformed reply" , __func__);return NL_SKIP ; } -struct nlattr *tb_peer[OVPN_GET_PEER_RESP_ATTR_MAX +1 ]; +struct nlattr *tb_peer[OVPN_A_PEER ]; -nla_parse (tb_peer,OVPN_GET_PEER_RESP_ATTR_MAX , -nla_data (tb[OVPN_ATTR_GET_PEER ]), -nla_len (tb[OVPN_ATTR_GET_PEER ]),NULL ); +nla_parse (tb_peer,OVPN_A_PEER_ID , +nla_data (tb[OVPN_A_PEER_ID ]), +nla_len (tb[OVPN_A_PEER_ID ]),NULL ); -if (!tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]) +if (!tb_peer[OVPN_A_PEER_ID ]) {msg (M_WARN ,"%s: no peer-id provided in reply" , __func__);return NL_SKIP ; } -uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]); +uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_A_PEER_ID ]);if (c->c2.tls_multi->dco_peer_id != peer_id) {return NL_SKIP ;
@@ -1033,11 +1089,11 @@ }dco_context_t *dco = &c->c1.tuntap->dco; -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_GET_PEER ); -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_GET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_GET ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_GET_PEER_ATTR_PEER_ID , peer_id); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peer_id);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg, dco_parse_peer, c, __func__);
src/openvpn/dco_linux.h +19 -0
@@ -31,9 +31,27 @@#include <netlink/socket.h> #include <netlink/netlink.h> +/* Defines to avoid mismatching with other platforms */ +#define OVPN_CMD_DEL_PEER OVPN_CMD_PEER_DEL_NTF +#define OVPN_CMD_SWAP_KEYS OVPN_CMD_KEY_SWAP_NTF +typedef enum ovpn_key_slot dco_key_slot_t ;typedef enum ovpn_cipher_alg dco_cipher_t ; +/* OVPN section */ + +enum ovpn_mode { +OVPN_MODE_P2P , +OVPN_MODE_MP , +}; + +enum ovpn_ifla_attrs { +IFLA_OVPN_UNSPEC =0 , +IFLA_OVPN_MODE , + + __IFLA_OVPN_AFTER_LAST, +IFLA_OVPN_MAX = __IFLA_OVPN_AFTER_LAST -1 , +}; typedef struct {
@@ -50,6 +68,7 @@int dco_message_type;int dco_message_peer_id; +int dco_message_key_id;int dco_del_peer_reason;uint64_t dco_read_bytes;uint64_t dco_write_bytes;
src/openvpn/networking_sitnl.c +1 -1
@@ -1354,7 +1354,7 @@struct rtattr *linkinfo =SITNL_NEST (&req.n,sizeof (req),IFLA_LINKINFO );SITNL_ADDATTR (&req.n,sizeof (req),IFLA_INFO_KIND , type,strlen (type) +1 );#if defined(ENABLE_DCO ) -if (arg && (strcmp (type,"ovpn-dco" ) ==0 )) +if (arg && (strcmp (type,OVPN_FAMILY_NAME ) ==0 )) {dco_context_t *dco = arg;struct rtattr *data =SITNL_NEST (&req.n,sizeof (req),IFLA_INFO_DATA );
src/openvpn/ovpn_dco_linux.h +73 -220
329 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/941?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I009f4e7ad38636f1c0b78d267561194c2bb4c051
Gerrit-Change-Number: 941
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange
Attention is currently required from: flichtenheld, its_Giaan, plaisthos.
ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/941?usp=email )
Change subject: Add support to "ovpn" aka "in upstream kernel"
......................................................................
Patch Set 1: Code-Review-1
(1 comment)
Patchset:
PS1:
I wouldc hange the commit title a bit...will suggest something.
Then I got this report:
2. a userspace nit probably not relevant to this submission: the daemon still reports "DCO version:" but with "N/A" value because that version file under /sys is not presented any more like it was with an out-of-tree v2 implementation
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/941?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I009f4e7ad38636f1c0b78d267561194c2bb4c051
Gerrit-Change-Number: 941
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 17 Apr 2025 09:58:03 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, its_Giaan, plaisthos.
ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/941?usp=email )
Change subject: Add support to "ovpn" aka "in upstream kernel"
......................................................................
Patch Set 1:
(1 comment)
Patchset:
PS1:
I also got the following:
1. is it expected for then tun iface to stay after the connection is brought down? If that matters, I'm using NetworkManager for managing my OpenVPN connections
Is openvpn not deleting the interface upon cleanup?
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/941?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I009f4e7ad38636f1c0b78d267561194c2bb4c051
Gerrit-Change-Number: 941
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 17 Apr 2025 10:01:32 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, its_Giaan, plaisthos.
ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/941?usp=email )
Change subject: Add support to "ovpn" aka "in upstream kernel"
......................................................................
Patch Set 1:
(1 comment)
Patchset:
PS1:
[re-adding comment as it was set a Resolved by accident]
I would change the commit title a bit...will suggest something.
Then I got this report:
2. a userspace nit probably not relevant to this submission: the daemon still reports "DCO version:" but with "N/A" value because that version file under /sys is not presented any more like it was with an out-of-tree v2 implementation
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/941?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I009f4e7ad38636f1c0b78d267561194c2bb4c051
Gerrit-Change-Number: 941
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 17 Apr 2025 10:02:39 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, its_Giaan, plaisthos.
ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/941?usp=email )
Change subject: Add support to "ovpn" aka "in upstream kernel"
......................................................................
Patch Set 1: -Code-Review
(2 comments)
Patchset:
PS1:
Quoted 1 line
I also got the following: […]
Gianmarco confirmed that openvpn cleans the interface up correctly. We need to check with the NM guy why this is happening under NM. Therefore this is not an issue with this patch.
PS1:
Quoted 1 line
[re-adding comment as it was set a Resolved by accident] […]
this is something that we could deal with in a separate patch.
Basically in-kernel modules do not have a separate "version" file.
We will have it when compiling the 'ovpn' through dkms, but we won't when using the in-kernel version.
Therefore we will have to extend the check and possibly print the kernel version when using the in-kernel one.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/941?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I009f4e7ad38636f1c0b78d267561194c2bb4c051
Gerrit-Change-Number: 941
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Thu, 17 Apr 2025 11:22:50 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: ordex <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: flichtenheld, its_Giaan, plaisthos.
ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/941?usp=email )
Change subject: Add support to "ovpn" aka "in upstream kernel"
......................................................................
Patch Set 1: Code-Review-1
(1 comment)
Patchset:
PS1:
I got this report:
2025-04-18 14:54:29 us=859916 dco_get_peer_stats: peer-id 0 2025-04-18 14:54:29 us=860232 dco_parse_peer: parsing message... 2025-04-18 14:54:29 us=860278 dco_parse_peer: malformed reply
followed by segmentation fault.
I think we did not port the incoming message parsing. and when errori g out it is crashing.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/941?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I009f4e7ad38636f1c0b78d267561194c2bb4c051
Gerrit-Change-Number: 941
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Sat, 19 Apr 2025 11:14:34 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
[Openvpn-devel] [L] Change in openvpn[master]: dco_linux: Introduce new uAPIs
In reply to a message not in the archiveAttention is currently required from: flichtenheld, its_Giaan, ordex, plaisthos.
Hello flichtenheld, ordex, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/941?usp=email
to look at the new patch set (#2).
The following approvals got outdated and were removed:
Code-Review-1 by ordex
Change subject: dco_linux: Introduce new uAPIs
......................................................................
dco_linux: Introduce new uAPIs
This patch updates the dco userspace API to
support communication with the new in-kernel
driver.
The main change involves updating the enums
used for Netlink messages to match the
definitions expected by the kernel module.
---
M src/openvpn/dco_linux.c
M src/openvpn/dco_linux.h
M src/openvpn/networking_sitnl.c
M src/openvpn/ovpn_dco_linux.h
4 files changed, 257 insertions(+), 329 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/41/941/2
src/openvpn/dco_linux.c +164 -108
@@ -96,7 +96,7 @@ }set_cloexec (nl_socket_get_fd (nl_sock)); - ret =genl_ctrl_resolve (nl_sock,OVPN_NL_NAME ); + ret =genl_ctrl_resolve (nl_sock,OVPN_FAMILY_NAME );if (ret <0 ) { msg(msglevel, "Cannot find ovpn_dco netlink component: %s",
@@ -109,7 +109,7 @@ }static struct nl_msg * -ovpn_dco_nlmsg_create (dco_context_t *dco,enum ovpn_nl_commands cmd) +ovpn_dco_nlmsg_create (dco_context_t *dco,int cmd) {struct nl_msg *nl_msg =nlmsg_alloc ();if (!nl_msg)
@@ -119,7 +119,7 @@ }genlmsg_put (nl_msg,0 ,0 , dco->ovpn_dco_id,0 ,0 , cmd,0 ); -NLA_PUT_U32 (nl_msg,OVPN_ATTR_IFINDEX , dco->ifindex); +NLA_PUT_U32 (nl_msg,OVPN_A_IFINDEX , dco->ifindex);return nl_msg; nla_put_failure:
@@ -231,20 +231,31 @@msg (D_DCO_DEBUG ,"%s: peer-id %d, fd %d, remote addr: %s" , __func__, peerid, sd, remotestr); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_NEW_PEER ); -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_NEW_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_NEW ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_PEER_ID , peerid); -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_SOCKET , sd); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_SOCKET , sd);/* Set the remote endpoint if defined (for UDP) */ if (remoteaddr) { remoteaddr =mapped_v4_to_v6 (remoteaddr, &gc); -int alen =af_addr_size (remoteaddr->sa_family); -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_SOCKADDR_REMOTE , alen, remoteaddr); +if (remoteaddr->sa_family ==AF_INET ) + { +NLA_PUT (nl_msg,OVPN_A_PEER_REMOTE_IPV4 ,sizeof (struct in_addr ), + &((struct sockaddr_in *)remoteaddr)->sin_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_REMOTE_PORT , ((struct sockaddr_in *)remoteaddr)->sin_port); + } +else if (remoteaddr->sa_family ==AF_INET6 ) + { +NLA_PUT (nl_msg,OVPN_A_PEER_REMOTE_IPV6 ,sizeof (struct in6_addr ), + &((struct sockaddr_in6 *)remoteaddr)->sin6_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_REMOTE_PORT , ((struct sockaddr_in6 *)remoteaddr)->sin6_port); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_REMOTE_IPV6_SCOPE_ID , ((struct sockaddr_in6 *)remoteaddr)->sin6_scope_id); + } }if (localaddr)
@@ -252,24 +263,26 @@ localaddr =mapped_v4_to_v6 (localaddr, &gc);if (localaddr->sa_family ==AF_INET ) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_LOCAL_IP ,sizeof (struct in_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_LOCAL_IPV4 ,sizeof (struct in_addr ), &((struct sockaddr_in *)localaddr)->sin_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_LOCAL_PORT , ((struct sockaddr_in *)localaddr)->sin_port); }else if (localaddr->sa_family ==AF_INET6 ) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_LOCAL_IP ,sizeof (struct in6_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_LOCAL_IPV6 ,sizeof (struct in6_addr ), &((struct sockaddr_in6 *)localaddr)->sin6_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_LOCAL_PORT , ((struct sockaddr_in6 *)localaddr)->sin6_port); } }/* Set the primary VPN IP addresses of the peer */ if (vpn_ipv4) { -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_IPV4 , vpn_ipv4->s_addr); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_VPN_IPV4 , vpn_ipv4->s_addr); }if (vpn_ipv6) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_IPV6 ,sizeof (struct in6_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_VPN_IPV6 ,sizeof (struct in6_addr ), vpn_ipv6); }nla_nest_end (nl_msg, attr);
@@ -481,7 +494,7 @@msg (D_DCO_DEBUG ,"%s: %s" , __func__, dev);ASSERT (tt->type ==DEV_TYPE_TUN ); -int ret =net_iface_new (ctx, dev,"ovpn-dco" , &tt->dco); +int ret =net_iface_new (ctx, dev,OVPN_FAMILY_NAME , &tt->dco);if (ret <0 ) {msg (D_DCO_DEBUG ,"Cannot create DCO interface %s: %d" , dev, ret);
@@ -515,22 +528,23 @@ {msg (D_DCO_DEBUG ,"%s: peer-id %d" , __func__, peerid); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_SWAP_KEYS ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_SWAP );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_SWAP_KEYS ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_KEYCONF );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_SWAP_KEYS_ATTR_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__); - -nla_put_failure:nlmsg_free (nl_msg);return ret; +nla_put_failure: +nlmsg_free (nl_msg); +return -1 ; }
@@ -539,21 +553,23 @@ {msg (D_DCO_DEBUG ,"%s: peer-id %d" , __func__, peerid); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_DEL_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_DEL );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_DEL_PEER ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_DEL_PEER_ATTR_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__); - +nlmsg_free (nl_msg); +return ret; nla_put_failure:nlmsg_free (nl_msg); + ret =-1 ;return ret; }
@@ -562,19 +578,20 @@ dco_del_key(dco_context_t *dco, unsigned int peerid, dco_key_slot_t slot) { +int ret = -EMSGSIZE ;msg (D_DCO_DEBUG ,"%s: peer-id %d, slot %d" , __func__, peerid, slot); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_DEL_KEY ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_DEL );if (!nl_msg) {return -ENOMEM ; } +struct nlattr *keyconf; -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_DEL_KEY ); -int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_DEL_KEY_ATTR_PEER_ID , peerid); -NLA_PUT_U8 (nl_msg,OVPN_DEL_KEY_ATTR_KEY_SLOT , slot); -nla_nest_end (nl_msg, attr); + keyconf =nla_nest_start (nl_msg,OVPN_A_KEYCONF ); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_SLOT , slot); +nla_nest_end (nl_msg, keyconf); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -596,7 +613,7 @@const size_t key_len =cipher_kt_key_size (ciphername);const int nonce_tail_len =8 ; -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_NEW_KEY ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_NEW );if (!nl_msg) {return -ENOMEM ;
@@ -605,33 +622,35 @@dco_cipher_t dco_cipher =dco_get_cipher (ciphername);int ret = -EMSGSIZE ; -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_NEW_KEY ); -NLA_PUT_U32 (nl_msg,OVPN_NEW_KEY_ATTR_PEER_ID , peerid); -NLA_PUT_U8 (nl_msg,OVPN_NEW_KEY_ATTR_KEY_SLOT , slot); -NLA_PUT_U8 (nl_msg,OVPN_NEW_KEY_ATTR_KEY_ID , keyid); -NLA_PUT_U16 (nl_msg,OVPN_NEW_KEY_ATTR_CIPHER_ALG , dco_cipher); + +struct nlattr *key_conf =nla_nest_start (nl_msg,OVPN_A_KEYCONF ); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_SLOT , slot); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_KEY_ID , keyid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_CIPHER_ALG , dco_cipher);struct nlattr *key_enc =nla_nest_start (nl_msg, -OVPN_NEW_KEY_ATTR_ENCRYPT_KEY ); +OVPN_A_KEYCONF_ENCRYPT_DIR );if (dco_cipher !=OVPN_CIPHER_ALG_NONE ) { -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_CIPHER_KEY , key_len, encrypt_key); -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_NONCE_TAIL , nonce_tail_len, +NLA_PUT (nl_msg,OVPN_A_KEYDIR_CIPHER_KEY , key_len, encrypt_key); +NLA_PUT (nl_msg,OVPN_A_KEYDIR_NONCE_TAIL , nonce_tail_len, encrypt_iv); }nla_nest_end (nl_msg, key_enc);struct nlattr *key_dec =nla_nest_start (nl_msg, -OVPN_NEW_KEY_ATTR_DECRYPT_KEY ); +OVPN_A_KEYCONF_DECRYPT_DIR );if (dco_cipher !=OVPN_CIPHER_ALG_NONE ) { -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_CIPHER_KEY , key_len, decrypt_key); -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_NONCE_TAIL , nonce_tail_len, +NLA_PUT (nl_msg,OVPN_A_KEYDIR_CIPHER_KEY , key_len, decrypt_key); +NLA_PUT (nl_msg,OVPN_A_KEYDIR_NONCE_TAIL , nonce_tail_len, decrypt_iv); }nla_nest_end (nl_msg, key_dec); -nla_nest_end (nl_msg, attr); +nla_nest_end (nl_msg, key_conf); + ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -647,18 +666,18 @@msg (D_DCO_DEBUG ,"%s: peer-id %d, keepalive %d/%d, mss %d" , __func__, peerid, keepalive_interval, keepalive_timeout, mss); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_SET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_SET );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_SET_PEER ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_PEER_ID , peerid); -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_KEEPALIVE_INTERVAL , +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_KEEPALIVE_INTERVAL , keepalive_interval); -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_KEEPALIVE_TIMEOUT , +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_KEEPALIVE_TIMEOUT , keepalive_timeout);nla_nest_end (nl_msg, attr);
@@ -707,7 +726,7 @@ }if (strncmp (nla_data (tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME ]), -OVPN_NL_MULTICAST_GROUP_PEERS , +OVPN_MCGRP_PEERS ,nla_len (tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME ])) !=0 ) {continue ;
@@ -720,7 +739,7 @@ }/** * Lookup the multicast id for OpenVPN. This method and its help method currently -* hardcode the lookup to OVPN_NL_NAME and OVPN_NL_MULTICAST_GROUP_PEERS but +* hardcode the lookup to OVPN_FAMILY_NAME and OVPN_MCGRP_PEERS but * extended in the future if we need to lookup more than one mcast id. */ static int
@@ -741,7 +760,7 @@genlmsg_put (nl_msg,0 ,0 , ctrlid,0 ,0 ,CTRL_CMD_GETFAMILY ,0 );int ret = -EMSGSIZE ; -NLA_PUT_STRING (nl_msg,CTRL_ATTR_FAMILY_NAME ,OVPN_NL_NAME ); +NLA_PUT_STRING (nl_msg,CTRL_ATTR_FAMILY_NAME ,OVPN_FAMILY_NAME ); ret =ovpn_nl_msg_send (dco, nl_msg, mcast_family_handler, dco, __func__);
@@ -757,38 +776,38 @@dco_context_t *dco = arg;struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg)); -struct nlattr *attrs[OVPN_ATTR_MAX +1 ]; +struct nlattr *attrs[OVPN_A_PEER_MAX +1 ];struct nlmsghdr *nlh =nlmsg_hdr (msg);if (!genlmsg_valid_hdr (nlh,0 )) {msg (D_DCO ,"ovpn-dco: invalid header" ); -return NL_SKIP ; +return NL_STOP ; } -if (nla_parse (attrs,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +if (nla_parse (attrs,OVPN_A_PEER_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL )) {msg (D_DCO ,"received bogus data from ovpn-dco" ); -return NL_SKIP ; +return NL_STOP ; }/* we must know which interface this message is referring to in order to * avoid mixing messages for other instances */ -if (!attrs[OVPN_ATTR_IFINDEX ]) +if (!attrs[OVPN_A_IFINDEX ]) {msg (D_DCO ,"ovpn-dco: Received message without ifindex" ); -return NL_SKIP ; +return NL_STOP ; } -uint32_t ifindex =nla_get_u32 (attrs[OVPN_ATTR_IFINDEX ]); +uint32_t ifindex =nla_get_u32 (attrs[OVPN_A_IFINDEX ]);if (ifindex != dco->ifindex) {msg (D_DCO_DEBUG ,"ovpn-dco: ignoring message (type=%d) for foreign ifindex %d" , gnlh->cmd, ifindex); -return NL_SKIP ; +return NL_STOP ; }/* based on the message type, we parse the subobject contained in the
@@ -800,40 +819,77 @@*/ switch (gnlh->cmd) { -case OVPN_CMD_DEL_PEER : +case OVPN_CMD_PEER_DEL_NTF : { -if (!attrs[OVPN_ATTR_DEL_PEER ]) +if (!attrs[OVPN_A_PEER ]) { -msg (D_DCO ,"ovpn-dco: no attributes in OVPN_DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no attributes in OVPN_PEER_DEL message" ); +return NL_STOP ; } -struct nlattr *dp_attrs[OVPN_DEL_PEER_ATTR_MAX +1 ]; -if (nla_parse_nested (dp_attrs,OVPN_DEL_PEER_ATTR_MAX , - attrs[OVPN_ATTR_DEL_PEER ],NULL )) +struct nlattr *dp_attrs[OVPN_A_PEER_MAX +1 ]; +if (nla_parse_nested (dp_attrs,OVPN_A_PEER_MAX , + attrs[OVPN_A_PEER ],NULL )) { -msg (D_DCO ,"received bogus del peer packet data from ovpn-dco" ); -return NL_SKIP ; +msg (D_DCO ,"received bogus peer del packet data from ovpn-dco" ); +return NL_STOP ; } -if (!dp_attrs[OVPN_DEL_PEER_ATTR_REASON ]) +if (!dp_attrs[OVPN_A_PEER_DEL_REASON ]) { -msg (D_DCO ,"ovpn-dco: no reason in DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no reason in PEER_DEL message" ); +return NL_STOP ; } -if (!dp_attrs[OVPN_DEL_PEER_ATTR_PEER_ID ]) +if (!dp_attrs[OVPN_A_PEER_ID ]) { -msg (D_DCO ,"ovpn-dco: no peer-id in DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no peer-id in PEER_DEL message" ); +return NL_STOP ; } -int reason =nla_get_u8 (dp_attrs[OVPN_DEL_PEER_ATTR_REASON ]); -unsigned int peerid =nla_get_u32 (dp_attrs[OVPN_DEL_PEER_ATTR_PEER_ID ]); +int reason =nla_get_u32 (dp_attrs[OVPN_A_PEER_DEL_REASON ]); +unsigned int peerid =nla_get_u32 (dp_attrs[OVPN_A_PEER_ID ]); -msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_DEL_PEER, ifindex: %d, peer-id %d, reason: %d" , +msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_PEER_DEL, ifindex: %d, peer-id %d, reason: %d" , ifindex, peerid, reason); dco->dco_message_peer_id = peerid; dco->dco_del_peer_reason = reason; - dco->dco_message_type =OVPN_CMD_DEL_PEER ; + dco->dco_message_type =OVPN_CMD_PEER_DEL_NTF ; + +break ; + } + +case OVPN_CMD_KEY_SWAP_NTF : + { +if (!attrs[OVPN_A_KEYCONF ]) + { +msg (D_DCO ,"ovpn-dco: no attributes in OVPN_KEY_SWAP message" ); +return NL_STOP ; + } + +struct nlattr *dp_attrs[OVPN_A_KEYCONF_MAX +1 ]; +if (nla_parse_nested (dp_attrs,OVPN_A_KEYCONF_MAX , + attrs[OVPN_A_KEYCONF ],NULL )) + { +msg (D_DCO ,"received bogus swap key packet data from ovpn-dco" ); +return NL_STOP ; + } +if (!dp_attrs[OVPN_A_KEYCONF_PEER_ID ]) + { +msg (D_DCO ,"ovpn-dco: no peer-id in KEY_SWAP message" ); +return NL_STOP ; + } +if (!dp_attrs[OVPN_A_KEYCONF_KEY_ID ]) + { +msg (D_DCO ,"ovpn-dco: no key-id in KEY_SWAP message" ); +return NL_STOP ; + } +int key_id =nla_get_u16 (dp_attrs[OVPN_A_KEYCONF_KEY_ID ]); +unsigned int peer_id =nla_get_u32 (dp_attrs[OVPN_A_KEYCONF_PEER_ID ]); + +msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_KEY_SWAP, ifindex: %d, peer-id %d, key-id: %d" , + ifindex, peer_id, key_id); + dco->dco_message_peer_id = peer_id; + dco->dco_message_key_id = key_id; + dco->dco_message_type =OVPN_CMD_KEY_SWAP_NTF ;break ; }
@@ -841,7 +897,7 @@default :msg (D_DCO ,"ovpn-dco: received unknown command: %d" , gnlh->cmd); dco->dco_message_type =0 ; -return NL_SKIP ; +return NL_STOP ; }return NL_OK ;
@@ -859,9 +915,9 @@static void dco_update_peer_stat (struct context_2 *c2,struct nlattr *tb[],uint32_t id) { -if (tb[OVPN_GET_PEER_RESP_ATTR_LINK_RX_BYTES ]) +if (tb[OVPN_A_PEER_LINK_RX_BYTES ]) { - c2->dco_read_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_LINK_RX_BYTES ]); + c2->dco_read_bytes =nla_get_u64 (tb[OVPN_A_PEER_LINK_RX_BYTES ]);msg (D_DCO_DEBUG ,"%s / dco_read_bytes: " counter_format, __func__, c2->dco_read_bytes); }
@@ -871,9 +927,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_LINK_TX_BYTES ]) +if (tb[OVPN_A_PEER_LINK_TX_BYTES ]) { - c2->dco_write_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_LINK_TX_BYTES ]); + c2->dco_write_bytes =nla_get_u64 (tb[OVPN_A_PEER_LINK_TX_BYTES ]);msg (D_DCO_DEBUG ,"%s / dco_write_bytes: " counter_format, __func__, c2->dco_write_bytes); }
@@ -883,9 +939,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_VPN_RX_BYTES ]) +if (tb[OVPN_A_PEER_VPN_RX_BYTES ]) { - c2->tun_read_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_VPN_RX_BYTES ]); + c2->tun_read_bytes =nla_get_u64 (tb[OVPN_A_PEER_VPN_RX_BYTES ]);msg (D_DCO_DEBUG ,"%s / tun_read_bytes: " counter_format, __func__, c2->tun_read_bytes); }
@@ -895,9 +951,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_VPN_TX_BYTES ]) +if (tb[OVPN_A_PEER_VPN_TX_BYTES ]) { - c2->tun_write_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_VPN_TX_BYTES ]); + c2->tun_write_bytes =nla_get_u64 (tb[OVPN_A_PEER_VPN_TX_BYTES ]);msg (D_DCO_DEBUG ,"%s / tun_write_bytes: " counter_format, __func__, c2->tun_write_bytes); }
@@ -911,33 +967,33 @@int dco_parse_peer_multi (struct nl_msg *msg,void *arg) { -struct nlattr *tb[OVPN_ATTR_MAX +1 ]; +struct nlattr *tb[OVPN_A_PEER_MAX ];struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg));msg (D_DCO_DEBUG ,"%s: parsing message..." , __func__); -nla_parse (tb,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +nla_parse (tb,OVPN_A_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL ); -if (!tb[OVPN_ATTR_GET_PEER ]) +if (!tb[OVPN_A_PEER_ID ]) {return NL_SKIP ; } -struct nlattr *tb_peer[OVPN_GET_PEER_RESP_ATTR_MAX +1 ]; +struct nlattr *tb_peer[OVPN_A_PEER_MAX ]; -nla_parse (tb_peer,OVPN_GET_PEER_RESP_ATTR_MAX , -nla_data (tb[OVPN_ATTR_GET_PEER ]), -nla_len (tb[OVPN_ATTR_GET_PEER ]),NULL ); +nla_parse (tb_peer,OVPN_A_PEER_MAX , +nla_data (tb[OVPN_A_PEER_ID ]), +nla_len (tb[OVPN_A_PEER_ID ]),NULL ); -if (!tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]) +if (!tb_peer[OVPN_A_PEER_ID ]) {msg (M_WARN ,"%s: no peer-id provided in reply" , __func__);return NL_SKIP ; }struct multi_context *m = arg; -uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]); +uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_A_PEER_ID ]);if (peer_id >= m->max_clients || !m->instances[peer_id]) {
@@ -957,7 +1013,7 @@ {msg (D_DCO_DEBUG ,"%s" , __func__); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_GET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_GET );nlmsg_hdr (nl_msg)->nlmsg_flags |=NLM_F_DUMP ;
@@ -979,33 +1035,33 @@ dco_parse_peer(struct nl_msg *msg, void *arg) { struct context *c = arg; -struct nlattr *tb[OVPN_ATTR_MAX +1 ]; +struct nlattr *tb[OVPN_A_MAX ];struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg));msg (D_DCO_DEBUG ,"%s: parsing message..." , __func__); -nla_parse (tb,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +nla_parse (tb,OVPN_A_PEER_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL ); -if (!tb[OVPN_ATTR_GET_PEER ]) +if (!tb[OVPN_A_PEER ]) {msg (D_DCO_DEBUG ,"%s: malformed reply" , __func__);return NL_SKIP ; } -struct nlattr *tb_peer[OVPN_GET_PEER_RESP_ATTR_MAX +1 ]; +struct nlattr *tb_peer[OVPN_A_PEER_MAX +1 ]; -nla_parse (tb_peer,OVPN_GET_PEER_RESP_ATTR_MAX , -nla_data (tb[OVPN_ATTR_GET_PEER ]), -nla_len (tb[OVPN_ATTR_GET_PEER ]),NULL ); +nla_parse (tb_peer,OVPN_A_PEER , +nla_data (tb[OVPN_A_PEER ]), +nla_len (tb[OVPN_A_PEER ]),NULL ); -if (!tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]) +if (!tb_peer[OVPN_A_PEER_ID ]) {msg (M_WARN ,"%s: no peer-id provided in reply" , __func__);return NL_SKIP ; } -uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]); +uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_A_PEER_ID ]);if (c->c2.tls_multi->dco_peer_id != peer_id) {return NL_SKIP ;
@@ -1033,11 +1089,11 @@ }dco_context_t *dco = &c->c1.tuntap->dco; -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_GET_PEER ); -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_GET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_GET ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_GET_PEER_ATTR_PEER_ID , peer_id); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peer_id);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg, dco_parse_peer, c, __func__);
src/openvpn/dco_linux.h +19 -0
@@ -31,9 +31,27 @@#include <netlink/socket.h> #include <netlink/netlink.h> +/* Defines to avoid mismatching with other platforms */ +#define OVPN_CMD_DEL_PEER OVPN_CMD_PEER_DEL_NTF +#define OVPN_CMD_SWAP_KEYS OVPN_CMD_KEY_SWAP_NTF +typedef enum ovpn_key_slot dco_key_slot_t ;typedef enum ovpn_cipher_alg dco_cipher_t ; +/* OVPN section */ + +enum ovpn_mode { +OVPN_MODE_P2P , +OVPN_MODE_MP , +}; + +enum ovpn_ifla_attrs { +IFLA_OVPN_UNSPEC =0 , +IFLA_OVPN_MODE , + + __IFLA_OVPN_AFTER_LAST, +IFLA_OVPN_MAX = __IFLA_OVPN_AFTER_LAST -1 , +}; typedef struct {
@@ -50,6 +68,7 @@int dco_message_type;int dco_message_peer_id; +int dco_message_key_id;int dco_del_peer_reason;uint64_t dco_read_bytes;uint64_t dco_write_bytes;
src/openvpn/networking_sitnl.c +1 -1
@@ -1354,7 +1354,7 @@struct rtattr *linkinfo =SITNL_NEST (&req.n,sizeof (req),IFLA_LINKINFO );SITNL_ADDATTR (&req.n,sizeof (req),IFLA_INFO_KIND , type,strlen (type) +1 );#if defined(ENABLE_DCO ) -if (arg && (strcmp (type,"ovpn-dco" ) ==0 )) +if (arg && (strcmp (type,OVPN_FAMILY_NAME ) ==0 )) {dco_context_t *dco = arg;struct rtattr *data =SITNL_NEST (&req.n,sizeof (req),IFLA_INFO_DATA );
src/openvpn/ovpn_dco_linux.h +73 -220
329 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/941?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I009f4e7ad38636f1c0b78d267561194c2bb4c051
Gerrit-Change-Number: 941
Gerrit-PatchSet: 2
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset
[Openvpn-devel] [L] Change in openvpn[master]: dco_linux: Introduce new uAPIs
In reply to a message not in the archiveAttention is currently required from: flichtenheld, its_Giaan, ordex, plaisthos.
ordex has uploaded a new patch set (#3) to the change originally created by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/941?usp=email )
Change subject: dco_linux: Introduce new uAPIs
......................................................................
dco_linux: Introduce new uAPIs
This patch updates the dco userspace API to
support communication with the new in-kernel
driver.
The main change involves updating the enums
used for Netlink messages to match the
definitions expected by the kernel module.
---
M src/openvpn/dco_linux.c
M src/openvpn/dco_linux.h
M src/openvpn/networking_sitnl.c
M src/openvpn/ovpn_dco_linux.h
4 files changed, 259 insertions(+), 329 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/41/941/3
src/openvpn/dco_linux.c +166 -108
@@ -96,7 +96,7 @@ }set_cloexec (nl_socket_get_fd (nl_sock)); - ret =genl_ctrl_resolve (nl_sock,OVPN_NL_NAME ); + ret =genl_ctrl_resolve (nl_sock,OVPN_FAMILY_NAME );if (ret <0 ) { msg(msglevel, "Cannot find ovpn_dco netlink component: %s",
@@ -109,7 +109,7 @@ }static struct nl_msg * -ovpn_dco_nlmsg_create (dco_context_t *dco,enum ovpn_nl_commands cmd) +ovpn_dco_nlmsg_create (dco_context_t *dco,int cmd) {struct nl_msg *nl_msg =nlmsg_alloc ();if (!nl_msg)
@@ -119,7 +119,7 @@ }genlmsg_put (nl_msg,0 ,0 , dco->ovpn_dco_id,0 ,0 , cmd,0 ); -NLA_PUT_U32 (nl_msg,OVPN_ATTR_IFINDEX , dco->ifindex); +NLA_PUT_U32 (nl_msg,OVPN_A_IFINDEX , dco->ifindex);return nl_msg; nla_put_failure:
@@ -231,20 +231,31 @@msg (D_DCO_DEBUG ,"%s: peer-id %d, fd %d, remote addr: %s" , __func__, peerid, sd, remotestr); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_NEW_PEER ); -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_NEW_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_NEW ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_PEER_ID , peerid); -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_SOCKET , sd); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_SOCKET , sd);/* Set the remote endpoint if defined (for UDP) */ if (remoteaddr) { remoteaddr =mapped_v4_to_v6 (remoteaddr, &gc); -int alen =af_addr_size (remoteaddr->sa_family); -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_SOCKADDR_REMOTE , alen, remoteaddr); +if (remoteaddr->sa_family ==AF_INET ) + { +NLA_PUT (nl_msg,OVPN_A_PEER_REMOTE_IPV4 ,sizeof (struct in_addr ), + &((struct sockaddr_in *)remoteaddr)->sin_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_REMOTE_PORT , ((struct sockaddr_in *)remoteaddr)->sin_port); + } +else if (remoteaddr->sa_family ==AF_INET6 ) + { +NLA_PUT (nl_msg,OVPN_A_PEER_REMOTE_IPV6 ,sizeof (struct in6_addr ), + &((struct sockaddr_in6 *)remoteaddr)->sin6_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_REMOTE_PORT , ((struct sockaddr_in6 *)remoteaddr)->sin6_port); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_REMOTE_IPV6_SCOPE_ID , ((struct sockaddr_in6 *)remoteaddr)->sin6_scope_id); + } }if (localaddr)
@@ -252,24 +263,26 @@ localaddr =mapped_v4_to_v6 (localaddr, &gc);if (localaddr->sa_family ==AF_INET ) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_LOCAL_IP ,sizeof (struct in_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_LOCAL_IPV4 ,sizeof (struct in_addr ), &((struct sockaddr_in *)localaddr)->sin_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_LOCAL_PORT , ((struct sockaddr_in *)localaddr)->sin_port); }else if (localaddr->sa_family ==AF_INET6 ) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_LOCAL_IP ,sizeof (struct in6_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_LOCAL_IPV6 ,sizeof (struct in6_addr ), &((struct sockaddr_in6 *)localaddr)->sin6_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_LOCAL_PORT , ((struct sockaddr_in6 *)localaddr)->sin6_port); } }/* Set the primary VPN IP addresses of the peer */ if (vpn_ipv4) { -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_IPV4 , vpn_ipv4->s_addr); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_VPN_IPV4 , vpn_ipv4->s_addr); }if (vpn_ipv6) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_IPV6 ,sizeof (struct in6_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_VPN_IPV6 ,sizeof (struct in6_addr ), vpn_ipv6); }nla_nest_end (nl_msg, attr);
@@ -481,7 +494,7 @@msg (D_DCO_DEBUG ,"%s: %s" , __func__, dev);ASSERT (tt->type ==DEV_TYPE_TUN ); -int ret =net_iface_new (ctx, dev,"ovpn-dco" , &tt->dco); +int ret =net_iface_new (ctx, dev,OVPN_FAMILY_NAME , &tt->dco);if (ret <0 ) {msg (D_DCO_DEBUG ,"Cannot create DCO interface %s: %d" , dev, ret);
@@ -515,22 +528,23 @@ {msg (D_DCO_DEBUG ,"%s: peer-id %d" , __func__, peerid); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_SWAP_KEYS ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_SWAP );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_SWAP_KEYS ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_KEYCONF );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_SWAP_KEYS_ATTR_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__); - -nla_put_failure:nlmsg_free (nl_msg);return ret; +nla_put_failure: +nlmsg_free (nl_msg); +return -1 ; }
@@ -539,21 +553,23 @@ {msg (D_DCO_DEBUG ,"%s: peer-id %d" , __func__, peerid); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_DEL_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_DEL );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_DEL_PEER ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_DEL_PEER_ATTR_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__); - +nlmsg_free (nl_msg); +return ret; nla_put_failure:nlmsg_free (nl_msg); + ret =-1 ;return ret; }
@@ -562,19 +578,20 @@ dco_del_key(dco_context_t *dco, unsigned int peerid, dco_key_slot_t slot) { +int ret = -EMSGSIZE ;msg (D_DCO_DEBUG ,"%s: peer-id %d, slot %d" , __func__, peerid, slot); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_DEL_KEY ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_DEL );if (!nl_msg) {return -ENOMEM ; } +struct nlattr *keyconf; -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_DEL_KEY ); -int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_DEL_KEY_ATTR_PEER_ID , peerid); -NLA_PUT_U8 (nl_msg,OVPN_DEL_KEY_ATTR_KEY_SLOT , slot); -nla_nest_end (nl_msg, attr); + keyconf =nla_nest_start (nl_msg,OVPN_A_KEYCONF ); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_SLOT , slot); +nla_nest_end (nl_msg, keyconf); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -596,7 +613,7 @@const size_t key_len =cipher_kt_key_size (ciphername);const int nonce_tail_len =8 ; -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_NEW_KEY ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_NEW );if (!nl_msg) {return -ENOMEM ;
@@ -605,33 +622,35 @@dco_cipher_t dco_cipher =dco_get_cipher (ciphername);int ret = -EMSGSIZE ; -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_NEW_KEY ); -NLA_PUT_U32 (nl_msg,OVPN_NEW_KEY_ATTR_PEER_ID , peerid); -NLA_PUT_U8 (nl_msg,OVPN_NEW_KEY_ATTR_KEY_SLOT , slot); -NLA_PUT_U8 (nl_msg,OVPN_NEW_KEY_ATTR_KEY_ID , keyid); -NLA_PUT_U16 (nl_msg,OVPN_NEW_KEY_ATTR_CIPHER_ALG , dco_cipher); + +struct nlattr *key_conf =nla_nest_start (nl_msg,OVPN_A_KEYCONF ); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_SLOT , slot); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_KEY_ID , keyid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_CIPHER_ALG , dco_cipher);struct nlattr *key_enc =nla_nest_start (nl_msg, -OVPN_NEW_KEY_ATTR_ENCRYPT_KEY ); +OVPN_A_KEYCONF_ENCRYPT_DIR );if (dco_cipher !=OVPN_CIPHER_ALG_NONE ) { -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_CIPHER_KEY , key_len, encrypt_key); -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_NONCE_TAIL , nonce_tail_len, +NLA_PUT (nl_msg,OVPN_A_KEYDIR_CIPHER_KEY , key_len, encrypt_key); +NLA_PUT (nl_msg,OVPN_A_KEYDIR_NONCE_TAIL , nonce_tail_len, encrypt_iv); }nla_nest_end (nl_msg, key_enc);struct nlattr *key_dec =nla_nest_start (nl_msg, -OVPN_NEW_KEY_ATTR_DECRYPT_KEY ); +OVPN_A_KEYCONF_DECRYPT_DIR );if (dco_cipher !=OVPN_CIPHER_ALG_NONE ) { -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_CIPHER_KEY , key_len, decrypt_key); -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_NONCE_TAIL , nonce_tail_len, +NLA_PUT (nl_msg,OVPN_A_KEYDIR_CIPHER_KEY , key_len, decrypt_key); +NLA_PUT (nl_msg,OVPN_A_KEYDIR_NONCE_TAIL , nonce_tail_len, decrypt_iv); }nla_nest_end (nl_msg, key_dec); -nla_nest_end (nl_msg, attr); +nla_nest_end (nl_msg, key_conf); + ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -647,18 +666,18 @@msg (D_DCO_DEBUG ,"%s: peer-id %d, keepalive %d/%d, mss %d" , __func__, peerid, keepalive_interval, keepalive_timeout, mss); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_SET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_SET );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_SET_PEER ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_PEER_ID , peerid); -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_KEEPALIVE_INTERVAL , +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_KEEPALIVE_INTERVAL , keepalive_interval); -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_KEEPALIVE_TIMEOUT , +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_KEEPALIVE_TIMEOUT , keepalive_timeout);nla_nest_end (nl_msg, attr);
@@ -707,7 +726,7 @@ }if (strncmp (nla_data (tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME ]), -OVPN_NL_MULTICAST_GROUP_PEERS , +OVPN_MCGRP_PEERS ,nla_len (tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME ])) !=0 ) {continue ;
@@ -720,7 +739,7 @@ }/** * Lookup the multicast id for OpenVPN. This method and its help method currently -* hardcode the lookup to OVPN_NL_NAME and OVPN_NL_MULTICAST_GROUP_PEERS but +* hardcode the lookup to OVPN_FAMILY_NAME and OVPN_MCGRP_PEERS but * extended in the future if we need to lookup more than one mcast id. */ static int
@@ -741,7 +760,7 @@genlmsg_put (nl_msg,0 ,0 , ctrlid,0 ,0 ,CTRL_CMD_GETFAMILY ,0 );int ret = -EMSGSIZE ; -NLA_PUT_STRING (nl_msg,CTRL_ATTR_FAMILY_NAME ,OVPN_NL_NAME ); +NLA_PUT_STRING (nl_msg,CTRL_ATTR_FAMILY_NAME ,OVPN_FAMILY_NAME ); ret =ovpn_nl_msg_send (dco, nl_msg, mcast_family_handler, dco, __func__);
@@ -757,38 +776,38 @@dco_context_t *dco = arg;struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg)); -struct nlattr *attrs[OVPN_ATTR_MAX +1 ]; +struct nlattr *attrs[OVPN_A_MAX +1 ];struct nlmsghdr *nlh =nlmsg_hdr (msg);if (!genlmsg_valid_hdr (nlh,0 )) {msg (D_DCO ,"ovpn-dco: invalid header" ); -return NL_SKIP ; +return NL_STOP ; } -if (nla_parse (attrs,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +if (nla_parse (attrs,OVPN_A_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL )) {msg (D_DCO ,"received bogus data from ovpn-dco" ); -return NL_SKIP ; +return NL_STOP ; }/* we must know which interface this message is referring to in order to * avoid mixing messages for other instances */ -if (!attrs[OVPN_ATTR_IFINDEX ]) +if (!attrs[OVPN_A_IFINDEX ]) {msg (D_DCO ,"ovpn-dco: Received message without ifindex" ); -return NL_SKIP ; +return NL_STOP ; } -uint32_t ifindex =nla_get_u32 (attrs[OVPN_ATTR_IFINDEX ]); +uint32_t ifindex =nla_get_u32 (attrs[OVPN_A_IFINDEX ]);if (ifindex != dco->ifindex) {msg (D_DCO_DEBUG ,"ovpn-dco: ignoring message (type=%d) for foreign ifindex %d" , gnlh->cmd, ifindex); -return NL_SKIP ; +return NL_STOP ; }/* based on the message type, we parse the subobject contained in the
@@ -800,40 +819,79 @@*/ switch (gnlh->cmd) { -case OVPN_CMD_DEL_PEER : +case OVPN_CMD_PEER_DEL_NTF : { -if (!attrs[OVPN_ATTR_DEL_PEER ]) +if (!attrs[OVPN_A_PEER ]) { -msg (D_DCO ,"ovpn-dco: no attributes in OVPN_DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no peer in PEER_DEL_NTF message" ); +return NL_STOP ; } -struct nlattr *dp_attrs[OVPN_DEL_PEER_ATTR_MAX +1 ]; -if (nla_parse_nested (dp_attrs,OVPN_DEL_PEER_ATTR_MAX , - attrs[OVPN_ATTR_DEL_PEER ],NULL )) +struct nlattr *dp_attrs[OVPN_A_PEER_MAX +1 ]; +if (nla_parse_nested (dp_attrs,OVPN_A_PEER_MAX , + attrs[OVPN_A_PEER ],NULL )) { -msg (D_DCO ,"received bogus del peer packet data from ovpn-dco" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: can't parse peer in PEER_DEL_NTF messsage" ); +return NL_STOP ; } -if (!dp_attrs[OVPN_DEL_PEER_ATTR_REASON ]) +if (!dp_attrs[OVPN_A_PEER_DEL_REASON ]) { -msg (D_DCO ,"ovpn-dco: no reason in DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no reason in PEER_DEL_NTF message" ); +return NL_STOP ; } -if (!dp_attrs[OVPN_DEL_PEER_ATTR_PEER_ID ]) +if (!dp_attrs[OVPN_A_PEER_ID ]) { -msg (D_DCO ,"ovpn-dco: no peer-id in DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no peer-id in PEER_DEL_NTF message" ); +return NL_STOP ; } -int reason =nla_get_u8 (dp_attrs[OVPN_DEL_PEER_ATTR_REASON ]); -unsigned int peerid =nla_get_u32 (dp_attrs[OVPN_DEL_PEER_ATTR_PEER_ID ]); -msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_DEL_PEER, ifindex: %d, peer-id %d, reason: %d" , +int reason =nla_get_u32 (dp_attrs[OVPN_A_PEER_DEL_REASON ]); +unsigned int peerid =nla_get_u32 (dp_attrs[OVPN_A_PEER_ID ]); + +msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_PEER_DEL_NTF, ifindex: %d, peer-id %u, reason: %d" , ifindex, peerid, reason); dco->dco_message_peer_id = peerid; dco->dco_del_peer_reason = reason; - dco->dco_message_type =OVPN_CMD_DEL_PEER ; + dco->dco_message_type =OVPN_CMD_PEER_DEL_NTF ; + +break ; + } + +case OVPN_CMD_KEY_SWAP_NTF : + { +if (!attrs[OVPN_A_KEYCONF ]) + { +msg (D_DCO ,"ovpn-dco: no keyconf in KEY_SWAP_NTF message" ); +return NL_STOP ; + } + +struct nlattr *dp_attrs[OVPN_A_KEYCONF_MAX +1 ]; +if (nla_parse_nested (dp_attrs,OVPN_A_KEYCONF_MAX , + attrs[OVPN_A_KEYCONF ],NULL )) + { +msg (D_DCO ,"ovpn-dco: can't parse keyconf in KEY_SWAP_NTF message" ); +return NL_STOP ; + } +if (!dp_attrs[OVPN_A_KEYCONF_PEER_ID ]) + { +msg (D_DCO ,"ovpn-dco: no peer-id in KEY_SWAP_NTF message" ); +return NL_STOP ; + } +if (!dp_attrs[OVPN_A_KEYCONF_KEY_ID ]) + { +msg (D_DCO ,"ovpn-dco: no key-id in KEY_SWAP_NTF message" ); +return NL_STOP ; + } + +int key_id =nla_get_u16 (dp_attrs[OVPN_A_KEYCONF_KEY_ID ]); +unsigned int peer_id =nla_get_u32 (dp_attrs[OVPN_A_KEYCONF_PEER_ID ]); + +msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_KEY_SWAP_NTF, ifindex: %d, peer-id %u, key-id: %d" , + ifindex, peer_id, key_id); + dco->dco_message_peer_id = peer_id; + dco->dco_message_key_id = key_id; + dco->dco_message_type =OVPN_CMD_KEY_SWAP_NTF ;break ; }
@@ -841,7 +899,7 @@default :msg (D_DCO ,"ovpn-dco: received unknown command: %d" , gnlh->cmd); dco->dco_message_type =0 ; -return NL_SKIP ; +return NL_STOP ; }return NL_OK ;
@@ -859,9 +917,9 @@static void dco_update_peer_stat (struct context_2 *c2,struct nlattr *tb[],uint32_t id) { -if (tb[OVPN_GET_PEER_RESP_ATTR_LINK_RX_BYTES ]) +if (tb[OVPN_A_PEER_LINK_RX_BYTES ]) { - c2->dco_read_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_LINK_RX_BYTES ]); + c2->dco_read_bytes =nla_get_u64 (tb[OVPN_A_PEER_LINK_RX_BYTES ]);msg (D_DCO_DEBUG ,"%s / dco_read_bytes: " counter_format, __func__, c2->dco_read_bytes); }
@@ -871,9 +929,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_LINK_TX_BYTES ]) +if (tb[OVPN_A_PEER_LINK_TX_BYTES ]) { - c2->dco_write_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_LINK_TX_BYTES ]); + c2->dco_write_bytes =nla_get_u64 (tb[OVPN_A_PEER_LINK_TX_BYTES ]);msg (D_DCO_DEBUG ,"%s / dco_write_bytes: " counter_format, __func__, c2->dco_write_bytes); }
@@ -883,9 +941,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_VPN_RX_BYTES ]) +if (tb[OVPN_A_PEER_VPN_RX_BYTES ]) { - c2->tun_read_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_VPN_RX_BYTES ]); + c2->tun_read_bytes =nla_get_u64 (tb[OVPN_A_PEER_VPN_RX_BYTES ]);msg (D_DCO_DEBUG ,"%s / tun_read_bytes: " counter_format, __func__, c2->tun_read_bytes); }
@@ -895,9 +953,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_VPN_TX_BYTES ]) +if (tb[OVPN_A_PEER_VPN_TX_BYTES ]) { - c2->tun_write_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_VPN_TX_BYTES ]); + c2->tun_write_bytes =nla_get_u64 (tb[OVPN_A_PEER_VPN_TX_BYTES ]);msg (D_DCO_DEBUG ,"%s / tun_write_bytes: " counter_format, __func__, c2->tun_write_bytes); }
@@ -911,33 +969,33 @@int dco_parse_peer_multi (struct nl_msg *msg,void *arg) { -struct nlattr *tb[OVPN_ATTR_MAX +1 ]; +struct nlattr *tb[OVPN_A_PEER_MAX ];struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg));msg (D_DCO_DEBUG ,"%s: parsing message..." , __func__); -nla_parse (tb,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +nla_parse (tb,OVPN_A_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL ); -if (!tb[OVPN_ATTR_GET_PEER ]) +if (!tb[OVPN_A_PEER_ID ]) {return NL_SKIP ; } -struct nlattr *tb_peer[OVPN_GET_PEER_RESP_ATTR_MAX +1 ]; +struct nlattr *tb_peer[OVPN_A_PEER_MAX ]; -nla_parse (tb_peer,OVPN_GET_PEER_RESP_ATTR_MAX , -nla_data (tb[OVPN_ATTR_GET_PEER ]), -nla_len (tb[OVPN_ATTR_GET_PEER ]),NULL ); +nla_parse (tb_peer,OVPN_A_PEER_MAX , +nla_data (tb[OVPN_A_PEER_ID ]), +nla_len (tb[OVPN_A_PEER_ID ]),NULL ); -if (!tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]) +if (!tb_peer[OVPN_A_PEER_ID ]) {msg (M_WARN ,"%s: no peer-id provided in reply" , __func__);return NL_SKIP ; }struct multi_context *m = arg; -uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]); +uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_A_PEER_ID ]);if (peer_id >= m->max_clients || !m->instances[peer_id]) {
@@ -957,7 +1015,7 @@ {msg (D_DCO_DEBUG ,"%s" , __func__); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_GET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_GET );nlmsg_hdr (nl_msg)->nlmsg_flags |=NLM_F_DUMP ;
@@ -979,33 +1037,33 @@ dco_parse_peer(struct nl_msg *msg, void *arg) { struct context *c = arg; -struct nlattr *tb[OVPN_ATTR_MAX +1 ]; +struct nlattr *tb[OVPN_A_MAX ];struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg));msg (D_DCO_DEBUG ,"%s: parsing message..." , __func__); -nla_parse (tb,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +nla_parse (tb,OVPN_A_PEER_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL ); -if (!tb[OVPN_ATTR_GET_PEER ]) +if (!tb[OVPN_A_PEER ]) {msg (D_DCO_DEBUG ,"%s: malformed reply" , __func__);return NL_SKIP ; } -struct nlattr *tb_peer[OVPN_GET_PEER_RESP_ATTR_MAX +1 ]; +struct nlattr *tb_peer[OVPN_A_PEER_MAX +1 ]; -nla_parse (tb_peer,OVPN_GET_PEER_RESP_ATTR_MAX , -nla_data (tb[OVPN_ATTR_GET_PEER ]), -nla_len (tb[OVPN_ATTR_GET_PEER ]),NULL ); +nla_parse (tb_peer,OVPN_A_PEER , +nla_data (tb[OVPN_A_PEER ]), +nla_len (tb[OVPN_A_PEER ]),NULL ); -if (!tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]) +if (!tb_peer[OVPN_A_PEER_ID ]) {msg (M_WARN ,"%s: no peer-id provided in reply" , __func__);return NL_SKIP ; } -uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]); +uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_A_PEER_ID ]);if (c->c2.tls_multi->dco_peer_id != peer_id) {return NL_SKIP ;
@@ -1033,11 +1091,11 @@ }dco_context_t *dco = &c->c1.tuntap->dco; -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_GET_PEER ); -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_GET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_GET ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_GET_PEER_ATTR_PEER_ID , peer_id); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peer_id);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg, dco_parse_peer, c, __func__);
src/openvpn/dco_linux.h +19 -0
@@ -31,9 +31,27 @@#include <netlink/socket.h> #include <netlink/netlink.h> +/* Defines to avoid mismatching with other platforms */ +#define OVPN_CMD_DEL_PEER OVPN_CMD_PEER_DEL_NTF +#define OVPN_CMD_SWAP_KEYS OVPN_CMD_KEY_SWAP_NTF +typedef enum ovpn_key_slot dco_key_slot_t ;typedef enum ovpn_cipher_alg dco_cipher_t ; +/* OVPN section */ + +enum ovpn_mode { +OVPN_MODE_P2P , +OVPN_MODE_MP , +}; + +enum ovpn_ifla_attrs { +IFLA_OVPN_UNSPEC =0 , +IFLA_OVPN_MODE , + + __IFLA_OVPN_AFTER_LAST, +IFLA_OVPN_MAX = __IFLA_OVPN_AFTER_LAST -1 , +}; typedef struct {
@@ -50,6 +68,7 @@int dco_message_type;int dco_message_peer_id; +int dco_message_key_id;int dco_del_peer_reason;uint64_t dco_read_bytes;uint64_t dco_write_bytes;
src/openvpn/networking_sitnl.c +1 -1
@@ -1354,7 +1354,7 @@struct rtattr *linkinfo =SITNL_NEST (&req.n,sizeof (req),IFLA_LINKINFO );SITNL_ADDATTR (&req.n,sizeof (req),IFLA_INFO_KIND , type,strlen (type) +1 );#if defined(ENABLE_DCO ) -if (arg && (strcmp (type,"ovpn-dco" ) ==0 )) +if (arg && (strcmp (type,OVPN_FAMILY_NAME ) ==0 )) {dco_context_t *dco = arg;struct rtattr *data =SITNL_NEST (&req.n,sizeof (req),IFLA_INFO_DATA );
src/openvpn/ovpn_dco_linux.h +73 -220
329 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/941?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I009f4e7ad38636f1c0b78d267561194c2bb4c051
Gerrit-Change-Number: 941
Gerrit-PatchSet: 3
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset
[Openvpn-devel] [L] Change in openvpn[master]: dco_linux: Introduce new uAPIs
In reply to a message not in the archiveAttention is currently required from: flichtenheld, its_Giaan, ordex, plaisthos.
ordex has uploaded a new patch set (#4) to the change originally created by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/941?usp=email )
Change subject: dco_linux: Introduce new uAPIs
......................................................................
dco_linux: Introduce new uAPIs
This patch updates the dco userspace API to
support communication with the new in-kernel
driver.
The main change involves updating the enums
used for Netlink messages to match the
definitions expected by the kernel module.
---
M src/openvpn/dco_linux.c
M src/openvpn/dco_linux.h
M src/openvpn/networking_sitnl.c
M src/openvpn/ovpn_dco_linux.h
4 files changed, 255 insertions(+), 330 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/41/941/4
src/openvpn/dco_linux.c +162 -109
@@ -96,7 +96,7 @@ }set_cloexec (nl_socket_get_fd (nl_sock)); - ret =genl_ctrl_resolve (nl_sock,OVPN_NL_NAME ); + ret =genl_ctrl_resolve (nl_sock,OVPN_FAMILY_NAME );if (ret <0 ) { msg(msglevel, "Cannot find ovpn_dco netlink component: %s",
@@ -109,7 +109,7 @@ }static struct nl_msg * -ovpn_dco_nlmsg_create (dco_context_t *dco,enum ovpn_nl_commands cmd) +ovpn_dco_nlmsg_create (dco_context_t *dco,int cmd) {struct nl_msg *nl_msg =nlmsg_alloc ();if (!nl_msg)
@@ -119,7 +119,7 @@ }genlmsg_put (nl_msg,0 ,0 , dco->ovpn_dco_id,0 ,0 , cmd,0 ); -NLA_PUT_U32 (nl_msg,OVPN_ATTR_IFINDEX , dco->ifindex); +NLA_PUT_U32 (nl_msg,OVPN_A_IFINDEX , dco->ifindex);return nl_msg; nla_put_failure:
@@ -231,20 +231,31 @@msg (D_DCO_DEBUG ,"%s: peer-id %d, fd %d, remote addr: %s" , __func__, peerid, sd, remotestr); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_NEW_PEER ); -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_NEW_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_NEW ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_PEER_ID , peerid); -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_SOCKET , sd); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_SOCKET , sd);/* Set the remote endpoint if defined (for UDP) */ if (remoteaddr) { remoteaddr =mapped_v4_to_v6 (remoteaddr, &gc); -int alen =af_addr_size (remoteaddr->sa_family); -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_SOCKADDR_REMOTE , alen, remoteaddr); +if (remoteaddr->sa_family ==AF_INET ) + { +NLA_PUT (nl_msg,OVPN_A_PEER_REMOTE_IPV4 ,sizeof (struct in_addr ), + &((struct sockaddr_in *)remoteaddr)->sin_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_REMOTE_PORT , ((struct sockaddr_in *)remoteaddr)->sin_port); + } +else if (remoteaddr->sa_family ==AF_INET6 ) + { +NLA_PUT (nl_msg,OVPN_A_PEER_REMOTE_IPV6 ,sizeof (struct in6_addr ), + &((struct sockaddr_in6 *)remoteaddr)->sin6_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_REMOTE_PORT , ((struct sockaddr_in6 *)remoteaddr)->sin6_port); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_REMOTE_IPV6_SCOPE_ID , ((struct sockaddr_in6 *)remoteaddr)->sin6_scope_id); + } }if (localaddr)
@@ -252,24 +263,26 @@ localaddr =mapped_v4_to_v6 (localaddr, &gc);if (localaddr->sa_family ==AF_INET ) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_LOCAL_IP ,sizeof (struct in_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_LOCAL_IPV4 ,sizeof (struct in_addr ), &((struct sockaddr_in *)localaddr)->sin_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_LOCAL_PORT , ((struct sockaddr_in *)localaddr)->sin_port); }else if (localaddr->sa_family ==AF_INET6 ) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_LOCAL_IP ,sizeof (struct in6_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_LOCAL_IPV6 ,sizeof (struct in6_addr ), &((struct sockaddr_in6 *)localaddr)->sin6_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_LOCAL_PORT , ((struct sockaddr_in6 *)localaddr)->sin6_port); } }/* Set the primary VPN IP addresses of the peer */ if (vpn_ipv4) { -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_IPV4 , vpn_ipv4->s_addr); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_VPN_IPV4 , vpn_ipv4->s_addr); }if (vpn_ipv6) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_IPV6 ,sizeof (struct in6_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_VPN_IPV6 ,sizeof (struct in6_addr ), vpn_ipv6); }nla_nest_end (nl_msg, attr);
@@ -481,7 +494,7 @@msg (D_DCO_DEBUG ,"%s: %s" , __func__, dev);ASSERT (tt->type ==DEV_TYPE_TUN ); -int ret =net_iface_new (ctx, dev,"ovpn-dco" , &tt->dco); +int ret =net_iface_new (ctx, dev,OVPN_FAMILY_NAME , &tt->dco);if (ret <0 ) {msg (D_DCO_DEBUG ,"Cannot create DCO interface %s: %d" , dev, ret);
@@ -515,22 +528,23 @@ {msg (D_DCO_DEBUG ,"%s: peer-id %d" , __func__, peerid); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_SWAP_KEYS ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_SWAP );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_SWAP_KEYS ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_KEYCONF );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_SWAP_KEYS_ATTR_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__); - -nla_put_failure:nlmsg_free (nl_msg);return ret; +nla_put_failure: +nlmsg_free (nl_msg); +return -1 ; }
@@ -539,21 +553,23 @@ {msg (D_DCO_DEBUG ,"%s: peer-id %d" , __func__, peerid); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_DEL_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_DEL );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_DEL_PEER ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_DEL_PEER_ATTR_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__); - +nlmsg_free (nl_msg); +return ret; nla_put_failure:nlmsg_free (nl_msg); + ret =-1 ;return ret; }
@@ -562,19 +578,20 @@ dco_del_key(dco_context_t *dco, unsigned int peerid, dco_key_slot_t slot) { +int ret = -EMSGSIZE ;msg (D_DCO_DEBUG ,"%s: peer-id %d, slot %d" , __func__, peerid, slot); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_DEL_KEY ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_DEL );if (!nl_msg) {return -ENOMEM ; } +struct nlattr *keyconf; -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_DEL_KEY ); -int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_DEL_KEY_ATTR_PEER_ID , peerid); -NLA_PUT_U8 (nl_msg,OVPN_DEL_KEY_ATTR_KEY_SLOT , slot); -nla_nest_end (nl_msg, attr); + keyconf =nla_nest_start (nl_msg,OVPN_A_KEYCONF ); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_SLOT , slot); +nla_nest_end (nl_msg, keyconf); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -596,7 +613,7 @@const size_t key_len =cipher_kt_key_size (ciphername);const int nonce_tail_len =8 ; -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_NEW_KEY ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_NEW );if (!nl_msg) {return -ENOMEM ;
@@ -605,33 +622,35 @@dco_cipher_t dco_cipher =dco_get_cipher (ciphername);int ret = -EMSGSIZE ; -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_NEW_KEY ); -NLA_PUT_U32 (nl_msg,OVPN_NEW_KEY_ATTR_PEER_ID , peerid); -NLA_PUT_U8 (nl_msg,OVPN_NEW_KEY_ATTR_KEY_SLOT , slot); -NLA_PUT_U8 (nl_msg,OVPN_NEW_KEY_ATTR_KEY_ID , keyid); -NLA_PUT_U16 (nl_msg,OVPN_NEW_KEY_ATTR_CIPHER_ALG , dco_cipher); + +struct nlattr *key_conf =nla_nest_start (nl_msg,OVPN_A_KEYCONF ); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_SLOT , slot); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_KEY_ID , keyid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_CIPHER_ALG , dco_cipher);struct nlattr *key_enc =nla_nest_start (nl_msg, -OVPN_NEW_KEY_ATTR_ENCRYPT_KEY ); +OVPN_A_KEYCONF_ENCRYPT_DIR );if (dco_cipher !=OVPN_CIPHER_ALG_NONE ) { -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_CIPHER_KEY , key_len, encrypt_key); -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_NONCE_TAIL , nonce_tail_len, +NLA_PUT (nl_msg,OVPN_A_KEYDIR_CIPHER_KEY , key_len, encrypt_key); +NLA_PUT (nl_msg,OVPN_A_KEYDIR_NONCE_TAIL , nonce_tail_len, encrypt_iv); }nla_nest_end (nl_msg, key_enc);struct nlattr *key_dec =nla_nest_start (nl_msg, -OVPN_NEW_KEY_ATTR_DECRYPT_KEY ); +OVPN_A_KEYCONF_DECRYPT_DIR );if (dco_cipher !=OVPN_CIPHER_ALG_NONE ) { -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_CIPHER_KEY , key_len, decrypt_key); -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_NONCE_TAIL , nonce_tail_len, +NLA_PUT (nl_msg,OVPN_A_KEYDIR_CIPHER_KEY , key_len, decrypt_key); +NLA_PUT (nl_msg,OVPN_A_KEYDIR_NONCE_TAIL , nonce_tail_len, decrypt_iv); }nla_nest_end (nl_msg, key_dec); -nla_nest_end (nl_msg, attr); +nla_nest_end (nl_msg, key_conf); + ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -647,18 +666,18 @@msg (D_DCO_DEBUG ,"%s: peer-id %d, keepalive %d/%d, mss %d" , __func__, peerid, keepalive_interval, keepalive_timeout, mss); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_SET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_SET );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_SET_PEER ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_PEER_ID , peerid); -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_KEEPALIVE_INTERVAL , +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_KEEPALIVE_INTERVAL , keepalive_interval); -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_KEEPALIVE_TIMEOUT , +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_KEEPALIVE_TIMEOUT , keepalive_timeout);nla_nest_end (nl_msg, attr);
@@ -707,7 +726,7 @@ }if (strncmp (nla_data (tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME ]), -OVPN_NL_MULTICAST_GROUP_PEERS , +OVPN_MCGRP_PEERS ,nla_len (tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME ])) !=0 ) {continue ;
@@ -720,7 +739,7 @@ }/** * Lookup the multicast id for OpenVPN. This method and its help method currently -* hardcode the lookup to OVPN_NL_NAME and OVPN_NL_MULTICAST_GROUP_PEERS but +* hardcode the lookup to OVPN_FAMILY_NAME and OVPN_MCGRP_PEERS but * extended in the future if we need to lookup more than one mcast id. */ static int
@@ -741,7 +760,7 @@genlmsg_put (nl_msg,0 ,0 , ctrlid,0 ,0 ,CTRL_CMD_GETFAMILY ,0 );int ret = -EMSGSIZE ; -NLA_PUT_STRING (nl_msg,CTRL_ATTR_FAMILY_NAME ,OVPN_NL_NAME ); +NLA_PUT_STRING (nl_msg,CTRL_ATTR_FAMILY_NAME ,OVPN_FAMILY_NAME ); ret =ovpn_nl_msg_send (dco, nl_msg, mcast_family_handler, dco, __func__);
@@ -757,38 +776,38 @@dco_context_t *dco = arg;struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg)); -struct nlattr *attrs[OVPN_ATTR_MAX +1 ]; +struct nlattr *attrs[OVPN_A_MAX +1 ];struct nlmsghdr *nlh =nlmsg_hdr (msg);if (!genlmsg_valid_hdr (nlh,0 )) {msg (D_DCO ,"ovpn-dco: invalid header" ); -return NL_SKIP ; +return NL_STOP ; } -if (nla_parse (attrs,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +if (nla_parse (attrs,OVPN_A_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL )) {msg (D_DCO ,"received bogus data from ovpn-dco" ); -return NL_SKIP ; +return NL_STOP ; }/* we must know which interface this message is referring to in order to * avoid mixing messages for other instances */ -if (!attrs[OVPN_ATTR_IFINDEX ]) +if (!attrs[OVPN_A_IFINDEX ]) {msg (D_DCO ,"ovpn-dco: Received message without ifindex" ); -return NL_SKIP ; +return NL_STOP ; } -uint32_t ifindex =nla_get_u32 (attrs[OVPN_ATTR_IFINDEX ]); +uint32_t ifindex =nla_get_u32 (attrs[OVPN_A_IFINDEX ]);if (ifindex != dco->ifindex) {msg (D_DCO_DEBUG ,"ovpn-dco: ignoring message (type=%d) for foreign ifindex %d" , gnlh->cmd, ifindex); -return NL_SKIP ; +return NL_STOP ; }/* based on the message type, we parse the subobject contained in the
@@ -800,48 +819,85 @@*/ switch (gnlh->cmd) { -case OVPN_CMD_DEL_PEER : +case OVPN_CMD_PEER_DEL_NTF : { -if (!attrs[OVPN_ATTR_DEL_PEER ]) +if (!attrs[OVPN_A_PEER ]) { -msg (D_DCO ,"ovpn-dco: no attributes in OVPN_DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no peer in PEER_DEL_NTF message" ); +return NL_STOP ; } -struct nlattr *dp_attrs[OVPN_DEL_PEER_ATTR_MAX +1 ]; -if (nla_parse_nested (dp_attrs,OVPN_DEL_PEER_ATTR_MAX , - attrs[OVPN_ATTR_DEL_PEER ],NULL )) +struct nlattr *dp_attrs[OVPN_A_PEER_MAX +1 ]; +if (nla_parse_nested (dp_attrs,OVPN_A_PEER_MAX , attrs[OVPN_A_PEER ], +NULL )) { -msg (D_DCO ,"received bogus del peer packet data from ovpn-dco" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: can't parse peer in PEER_DEL_NTF messsage" ); +return NL_STOP ; } -if (!dp_attrs[OVPN_DEL_PEER_ATTR_REASON ]) +if (!dp_attrs[OVPN_A_PEER_DEL_REASON ]) { -msg (D_DCO ,"ovpn-dco: no reason in DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no reason in PEER_DEL_NTF message" ); +return NL_STOP ; } -if (!dp_attrs[OVPN_DEL_PEER_ATTR_PEER_ID ]) +if (!dp_attrs[OVPN_A_PEER_ID ]) { -msg (D_DCO ,"ovpn-dco: no peer-id in DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no peer-id in PEER_DEL_NTF message" ); +return NL_STOP ; } -int reason =nla_get_u8 (dp_attrs[OVPN_DEL_PEER_ATTR_REASON ]); -unsigned int peerid =nla_get_u32 (dp_attrs[OVPN_DEL_PEER_ATTR_PEER_ID ]); -msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_DEL_PEER, ifindex: %d, peer-id %d, reason: %d" , +int reason =nla_get_u32 (dp_attrs[OVPN_A_PEER_DEL_REASON ]); +unsigned int peerid =nla_get_u32 (dp_attrs[OVPN_A_PEER_ID ]); + +msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_PEER_DEL_NTF, ifindex: %d, peer-id %u, reason: %d" , ifindex, peerid, reason); dco->dco_message_peer_id = peerid; dco->dco_del_peer_reason = reason; - dco->dco_message_type =OVPN_CMD_DEL_PEER ; + dco->dco_message_type =OVPN_CMD_PEER_DEL_NTF ; +break ; + } +case OVPN_CMD_KEY_SWAP_NTF : + { +if (!attrs[OVPN_A_KEYCONF ]) + { +msg (D_DCO ,"ovpn-dco: no keyconf in KEY_SWAP_NTF message" ); +return NL_STOP ; + } + +struct nlattr *dp_attrs[OVPN_A_KEYCONF_MAX +1 ]; +if (nla_parse_nested (dp_attrs,OVPN_A_KEYCONF_MAX , + attrs[OVPN_A_KEYCONF ],NULL )) + { +msg (D_DCO ,"ovpn-dco: can't parse keyconf in KEY_SWAP_NTF message" ); +return NL_STOP ; + } +if (!dp_attrs[OVPN_A_KEYCONF_PEER_ID ]) + { +msg (D_DCO ,"ovpn-dco: no peer-id in KEY_SWAP_NTF message" ); +return NL_STOP ; + } +if (!dp_attrs[OVPN_A_KEYCONF_KEY_ID ]) + { +msg (D_DCO ,"ovpn-dco: no key-id in KEY_SWAP_NTF message" ); +return NL_STOP ; + } + +int key_id =nla_get_u16 (dp_attrs[OVPN_A_KEYCONF_KEY_ID ]); +unsigned int peer_id =nla_get_u32 (dp_attrs[OVPN_A_KEYCONF_PEER_ID ]); + +msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_KEY_SWAP_NTF, ifindex: %d, peer-id %u, key-id: %d" , + ifindex, peer_id, key_id); + dco->dco_message_peer_id = peer_id; + dco->dco_message_key_id = key_id; + dco->dco_message_type =OVPN_CMD_KEY_SWAP_NTF ;break ; }default :msg (D_DCO ,"ovpn-dco: received unknown command: %d" , gnlh->cmd); dco->dco_message_type =0 ; -return NL_SKIP ; +return NL_STOP ; }return NL_OK ;
@@ -859,9 +915,9 @@static void dco_update_peer_stat (struct context_2 *c2,struct nlattr *tb[],uint32_t id) { -if (tb[OVPN_GET_PEER_RESP_ATTR_LINK_RX_BYTES ]) +if (tb[OVPN_A_PEER_LINK_RX_BYTES ]) { - c2->dco_read_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_LINK_RX_BYTES ]); + c2->dco_read_bytes =nla_get_u64 (tb[OVPN_A_PEER_LINK_RX_BYTES ]);msg (D_DCO_DEBUG ,"%s / dco_read_bytes: " counter_format, __func__, c2->dco_read_bytes); }
@@ -871,9 +927,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_LINK_TX_BYTES ]) +if (tb[OVPN_A_PEER_LINK_TX_BYTES ]) { - c2->dco_write_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_LINK_TX_BYTES ]); + c2->dco_write_bytes =nla_get_u64 (tb[OVPN_A_PEER_LINK_TX_BYTES ]);msg (D_DCO_DEBUG ,"%s / dco_write_bytes: " counter_format, __func__, c2->dco_write_bytes); }
@@ -883,9 +939,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_VPN_RX_BYTES ]) +if (tb[OVPN_A_PEER_VPN_RX_BYTES ]) { - c2->tun_read_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_VPN_RX_BYTES ]); + c2->tun_read_bytes =nla_get_u64 (tb[OVPN_A_PEER_VPN_RX_BYTES ]);msg (D_DCO_DEBUG ,"%s / tun_read_bytes: " counter_format, __func__, c2->tun_read_bytes); }
@@ -895,9 +951,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_VPN_TX_BYTES ]) +if (tb[OVPN_A_PEER_VPN_TX_BYTES ]) { - c2->tun_write_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_VPN_TX_BYTES ]); + c2->tun_write_bytes =nla_get_u64 (tb[OVPN_A_PEER_VPN_TX_BYTES ]);msg (D_DCO_DEBUG ,"%s / tun_write_bytes: " counter_format, __func__, c2->tun_write_bytes); }
@@ -911,33 +967,30 @@int dco_parse_peer_multi (struct nl_msg *msg,void *arg) { -struct nlattr *tb[OVPN_ATTR_MAX +1 ]; +struct nlattr *tb[OVPN_A_MAX +1 ];struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg));msg (D_DCO_DEBUG ,"%s: parsing message..." , __func__); -nla_parse (tb,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +nla_parse (tb,OVPN_A_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL ); -if (!tb[OVPN_ATTR_GET_PEER ]) +if (!tb[OVPN_A_PEER ]) {return NL_SKIP ; } -struct nlattr *tb_peer[OVPN_GET_PEER_RESP_ATTR_MAX +1 ]; +struct nlattr *tb_peer[OVPN_A_PEER_MAX +1 ]; +nla_parse_nested (tb_peer,OVPN_A_PEER_MAX , tb[OVPN_A_PEER ],NULL ); -nla_parse (tb_peer,OVPN_GET_PEER_RESP_ATTR_MAX , -nla_data (tb[OVPN_ATTR_GET_PEER ]), -nla_len (tb[OVPN_ATTR_GET_PEER ]),NULL ); - -if (!tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]) +if (!tb_peer[OVPN_A_PEER_ID ]) {msg (M_WARN ,"%s: no peer-id provided in reply" , __func__);return NL_SKIP ; }struct multi_context *m = arg; -uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]); +uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_A_PEER_ID ]);if (peer_id >= m->max_clients || !m->instances[peer_id]) {
@@ -957,7 +1010,7 @@ {msg (D_DCO_DEBUG ,"%s" , __func__); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_GET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_GET );nlmsg_hdr (nl_msg)->nlmsg_flags |=NLM_F_DUMP ;
@@ -979,33 +1032,33 @@ dco_parse_peer(struct nl_msg *msg, void *arg) { struct context *c = arg; -struct nlattr *tb[OVPN_ATTR_MAX +1 ]; +struct nlattr *tb[OVPN_A_MAX ];struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg));msg (D_DCO_DEBUG ,"%s: parsing message..." , __func__); -nla_parse (tb,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +nla_parse (tb,OVPN_A_PEER_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL ); -if (!tb[OVPN_ATTR_GET_PEER ]) +if (!tb[OVPN_A_PEER ]) {msg (D_DCO_DEBUG ,"%s: malformed reply" , __func__);return NL_SKIP ; } -struct nlattr *tb_peer[OVPN_GET_PEER_RESP_ATTR_MAX +1 ]; +struct nlattr *tb_peer[OVPN_A_PEER_MAX +1 ]; -nla_parse (tb_peer,OVPN_GET_PEER_RESP_ATTR_MAX , -nla_data (tb[OVPN_ATTR_GET_PEER ]), -nla_len (tb[OVPN_ATTR_GET_PEER ]),NULL ); +nla_parse (tb_peer,OVPN_A_PEER , +nla_data (tb[OVPN_A_PEER ]), +nla_len (tb[OVPN_A_PEER ]),NULL ); -if (!tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]) +if (!tb_peer[OVPN_A_PEER_ID ]) {msg (M_WARN ,"%s: no peer-id provided in reply" , __func__);return NL_SKIP ; } -uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]); +uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_A_PEER_ID ]);if (c->c2.tls_multi->dco_peer_id != peer_id) {return NL_SKIP ;
@@ -1033,11 +1086,11 @@ }dco_context_t *dco = &c->c1.tuntap->dco; -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_GET_PEER ); -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_GET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_GET ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_GET_PEER_ATTR_PEER_ID , peer_id); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peer_id);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg, dco_parse_peer, c, __func__);
src/openvpn/dco_linux.h +19 -0
@@ -31,9 +31,27 @@#include <netlink/socket.h> #include <netlink/netlink.h> +/* Defines to avoid mismatching with other platforms */ +#define OVPN_CMD_DEL_PEER OVPN_CMD_PEER_DEL_NTF +#define OVPN_CMD_SWAP_KEYS OVPN_CMD_KEY_SWAP_NTF +typedef enum ovpn_key_slot dco_key_slot_t ;typedef enum ovpn_cipher_alg dco_cipher_t ; +/* OVPN section */ + +enum ovpn_mode { +OVPN_MODE_P2P , +OVPN_MODE_MP , +}; + +enum ovpn_ifla_attrs { +IFLA_OVPN_UNSPEC =0 , +IFLA_OVPN_MODE , + + __IFLA_OVPN_AFTER_LAST, +IFLA_OVPN_MAX = __IFLA_OVPN_AFTER_LAST -1 , +}; typedef struct {
@@ -50,6 +68,7 @@int dco_message_type;int dco_message_peer_id; +int dco_message_key_id;int dco_del_peer_reason;uint64_t dco_read_bytes;uint64_t dco_write_bytes;
src/openvpn/networking_sitnl.c +1 -1
@@ -1354,7 +1354,7 @@struct rtattr *linkinfo =SITNL_NEST (&req.n,sizeof (req),IFLA_LINKINFO );SITNL_ADDATTR (&req.n,sizeof (req),IFLA_INFO_KIND , type,strlen (type) +1 );#if defined(ENABLE_DCO ) -if (arg && (strcmp (type,"ovpn-dco" ) ==0 )) +if (arg && (strcmp (type,OVPN_FAMILY_NAME ) ==0 )) {dco_context_t *dco = arg;struct rtattr *data =SITNL_NEST (&req.n,sizeof (req),IFLA_INFO_DATA );
src/openvpn/ovpn_dco_linux.h +73 -220
329 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/941?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I009f4e7ad38636f1c0b78d267561194c2bb4c051
Gerrit-Change-Number: 941
Gerrit-PatchSet: 4
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset
[Openvpn-devel] [L] Change in openvpn[master]: dco_linux: Introduce new uAPIs
In reply to a message not in the archiveAttention is currently required from: flichtenheld, its_Giaan, plaisthos.
ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/941?usp=email )
Change subject: dco_linux: Introduce new uAPIs
......................................................................
Patch Set 4: Code-Review+2
(1 comment)
Patchset:
PS4:
This patch now looks good to me (Gianmarco is away this week, so I personally pushed v4 without waiting for him)
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/941?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I009f4e7ad38636f1c0b78d267561194c2bb4c051
Gerrit-Change-Number: 941
Gerrit-PatchSet: 4
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Mon, 28 Apr 2025 08:19:19 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
[Openvpn-devel] [L] Change in openvpn[master]: dco_linux: Introduce new uAPIs
In reply to a message not in the archiveAttention is currently required from: flichtenheld, its_Giaan, ordex, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/941?usp=email )
Change subject: dco_linux: Introduce new uAPIs
......................................................................
Patch Set 4: Code-Review-1
(5 comments)
Patchset:
PS4:
Overall it looks relatively straightforward, with most of the changes just replacing one define with another - easy enough. Testing to come.
There are a few changes that break the style of this module, and I see no strong reason why these are done, so -1 for now.
File src/openvpn/dco_linux.c:
http://gerrit.openvpn.net/c/openvpn/+/941/comment/006d280c_8ba3e1fe :
PS4, Line 547: return -1;
this change looks unneccessary?
http://gerrit.openvpn.net/c/openvpn/+/941/comment/91377007_60a5d367 :
PS4, Line 574: }
same here... the code style with "one common free()/return at the end" is kept in other places (like dco_del_key()), so why change it here, and in a different style than in dco_swap_keys()?
http://gerrit.openvpn.net/c/openvpn/+/941/comment/ed9e335b_8afd8a97 :
PS4, Line 591: keyconf = nla_nest_start(nl_msg, OVPN_A_KEYCONF);
why wrap differently, and not keep struct nlattr * nla_nest_start()...? Line too long?
http://gerrit.openvpn.net/c/openvpn/+/941/comment/333dacb6_0b189629 :
PS4, Line 860: case OVPN_CMD_KEY_SWAP_NTF:
what is KEY_SWAP_NTF? That's a new thing :-)
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/941?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I009f4e7ad38636f1c0b78d267561194c2bb4c051
Gerrit-Change-Number: 941
Gerrit-PatchSet: 4
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Fri, 02 May 2025 20:35:00 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
[Openvpn-devel] [L] Change in openvpn[master]: dco_linux: Introduce new uAPIs
In reply to a message not in the archiveAttention is currently required from: cron2, flichtenheld, its_Giaan, ordex, plaisthos.
Hello cron2, flichtenheld, ordex, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/941?usp=email
to look at the new patch set (#5).
The following approvals got outdated and were removed:
Code-Review+2 by ordex, Code-Review-1 by cron2
The change is no longer submittable: Code-Review and checks~ChecksSubmitRule are unsatisfied now.
Change subject: dco_linux: Introduce new uAPIs
......................................................................
dco_linux: Introduce new uAPIs
This patch updates the dco userspace API to
support communication with the new in-kernel
driver.
The main change involves updating the enums
used for Netlink messages to match the
definitions expected by the kernel module.
---
M src/openvpn/dco_linux.c
M src/openvpn/dco_linux.h
M src/openvpn/networking_sitnl.c
M src/openvpn/ovpn_dco_linux.h
4 files changed, 248 insertions(+), 327 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/41/941/5
src/openvpn/dco_linux.c +155 -106
@@ -96,7 +96,7 @@ }set_cloexec (nl_socket_get_fd (nl_sock)); - ret =genl_ctrl_resolve (nl_sock,OVPN_NL_NAME ); + ret =genl_ctrl_resolve (nl_sock,OVPN_FAMILY_NAME );if (ret <0 ) { msg(msglevel, "Cannot find ovpn_dco netlink component: %s",
@@ -109,7 +109,7 @@ }static struct nl_msg * -ovpn_dco_nlmsg_create (dco_context_t *dco,enum ovpn_nl_commands cmd) +ovpn_dco_nlmsg_create (dco_context_t *dco,int cmd) {struct nl_msg *nl_msg =nlmsg_alloc ();if (!nl_msg)
@@ -119,7 +119,7 @@ }genlmsg_put (nl_msg,0 ,0 , dco->ovpn_dco_id,0 ,0 , cmd,0 ); -NLA_PUT_U32 (nl_msg,OVPN_ATTR_IFINDEX , dco->ifindex); +NLA_PUT_U32 (nl_msg,OVPN_A_IFINDEX , dco->ifindex);return nl_msg; nla_put_failure:
@@ -231,20 +231,31 @@msg (D_DCO_DEBUG ,"%s: peer-id %d, fd %d, remote addr: %s" , __func__, peerid, sd, remotestr); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_NEW_PEER ); -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_NEW_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_NEW ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_PEER_ID , peerid); -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_SOCKET , sd); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_SOCKET , sd);/* Set the remote endpoint if defined (for UDP) */ if (remoteaddr) { remoteaddr =mapped_v4_to_v6 (remoteaddr, &gc); -int alen =af_addr_size (remoteaddr->sa_family); -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_SOCKADDR_REMOTE , alen, remoteaddr); +if (remoteaddr->sa_family ==AF_INET ) + { +NLA_PUT (nl_msg,OVPN_A_PEER_REMOTE_IPV4 ,sizeof (struct in_addr ), + &((struct sockaddr_in *)remoteaddr)->sin_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_REMOTE_PORT , ((struct sockaddr_in *)remoteaddr)->sin_port); + } +else if (remoteaddr->sa_family ==AF_INET6 ) + { +NLA_PUT (nl_msg,OVPN_A_PEER_REMOTE_IPV6 ,sizeof (struct in6_addr ), + &((struct sockaddr_in6 *)remoteaddr)->sin6_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_REMOTE_PORT , ((struct sockaddr_in6 *)remoteaddr)->sin6_port); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_REMOTE_IPV6_SCOPE_ID , ((struct sockaddr_in6 *)remoteaddr)->sin6_scope_id); + } }if (localaddr)
@@ -252,24 +263,26 @@ localaddr =mapped_v4_to_v6 (localaddr, &gc);if (localaddr->sa_family ==AF_INET ) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_LOCAL_IP ,sizeof (struct in_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_LOCAL_IPV4 ,sizeof (struct in_addr ), &((struct sockaddr_in *)localaddr)->sin_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_LOCAL_PORT , ((struct sockaddr_in *)localaddr)->sin_port); }else if (localaddr->sa_family ==AF_INET6 ) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_LOCAL_IP ,sizeof (struct in6_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_LOCAL_IPV6 ,sizeof (struct in6_addr ), &((struct sockaddr_in6 *)localaddr)->sin6_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_LOCAL_PORT , ((struct sockaddr_in6 *)localaddr)->sin6_port); } }/* Set the primary VPN IP addresses of the peer */ if (vpn_ipv4) { -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_IPV4 , vpn_ipv4->s_addr); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_VPN_IPV4 , vpn_ipv4->s_addr); }if (vpn_ipv6) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_IPV6 ,sizeof (struct in6_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_VPN_IPV6 ,sizeof (struct in6_addr ), vpn_ipv6); }nla_nest_end (nl_msg, attr);
@@ -481,7 +494,7 @@msg (D_DCO_DEBUG ,"%s: %s" , __func__, dev);ASSERT (tt->type ==DEV_TYPE_TUN ); -int ret =net_iface_new (ctx, dev,"ovpn-dco" , &tt->dco); +int ret =net_iface_new (ctx, dev,OVPN_FAMILY_NAME , &tt->dco);if (ret <0 ) {msg (D_DCO_DEBUG ,"Cannot create DCO interface %s: %d" , dev, ret);
@@ -515,15 +528,15 @@ {msg (D_DCO_DEBUG ,"%s: peer-id %d" , __func__, peerid); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_SWAP_KEYS ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_SWAP );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_SWAP_KEYS ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_KEYCONF );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_SWAP_KEYS_ATTR_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -539,15 +552,15 @@ {msg (D_DCO_DEBUG ,"%s: peer-id %d" , __func__, peerid); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_DEL_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_DEL );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_DEL_PEER ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_DEL_PEER_ATTR_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -562,19 +575,19 @@ dco_del_key(dco_context_t *dco, unsigned int peerid, dco_key_slot_t slot) { +int ret = -EMSGSIZE ;msg (D_DCO_DEBUG ,"%s: peer-id %d, slot %d" , __func__, peerid, slot); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_DEL_KEY ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_DEL );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_DEL_KEY ); -int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_DEL_KEY_ATTR_PEER_ID , peerid); -NLA_PUT_U8 (nl_msg,OVPN_DEL_KEY_ATTR_KEY_SLOT , slot); -nla_nest_end (nl_msg, attr); +struct nlattr *keyconf =nla_nest_start (nl_msg,OVPN_A_KEYCONF ); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_SLOT , slot); +nla_nest_end (nl_msg, keyconf); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -596,7 +609,7 @@const size_t key_len =cipher_kt_key_size (ciphername);const int nonce_tail_len =8 ; -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_NEW_KEY ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_NEW );if (!nl_msg) {return -ENOMEM ;
@@ -605,33 +618,35 @@dco_cipher_t dco_cipher =dco_get_cipher (ciphername);int ret = -EMSGSIZE ; -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_NEW_KEY ); -NLA_PUT_U32 (nl_msg,OVPN_NEW_KEY_ATTR_PEER_ID , peerid); -NLA_PUT_U8 (nl_msg,OVPN_NEW_KEY_ATTR_KEY_SLOT , slot); -NLA_PUT_U8 (nl_msg,OVPN_NEW_KEY_ATTR_KEY_ID , keyid); -NLA_PUT_U16 (nl_msg,OVPN_NEW_KEY_ATTR_CIPHER_ALG , dco_cipher); + +struct nlattr *key_conf =nla_nest_start (nl_msg,OVPN_A_KEYCONF ); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_SLOT , slot); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_KEY_ID , keyid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_CIPHER_ALG , dco_cipher);struct nlattr *key_enc =nla_nest_start (nl_msg, -OVPN_NEW_KEY_ATTR_ENCRYPT_KEY ); +OVPN_A_KEYCONF_ENCRYPT_DIR );if (dco_cipher !=OVPN_CIPHER_ALG_NONE ) { -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_CIPHER_KEY , key_len, encrypt_key); -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_NONCE_TAIL , nonce_tail_len, +NLA_PUT (nl_msg,OVPN_A_KEYDIR_CIPHER_KEY , key_len, encrypt_key); +NLA_PUT (nl_msg,OVPN_A_KEYDIR_NONCE_TAIL , nonce_tail_len, encrypt_iv); }nla_nest_end (nl_msg, key_enc);struct nlattr *key_dec =nla_nest_start (nl_msg, -OVPN_NEW_KEY_ATTR_DECRYPT_KEY ); +OVPN_A_KEYCONF_DECRYPT_DIR );if (dco_cipher !=OVPN_CIPHER_ALG_NONE ) { -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_CIPHER_KEY , key_len, decrypt_key); -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_NONCE_TAIL , nonce_tail_len, +NLA_PUT (nl_msg,OVPN_A_KEYDIR_CIPHER_KEY , key_len, decrypt_key); +NLA_PUT (nl_msg,OVPN_A_KEYDIR_NONCE_TAIL , nonce_tail_len, decrypt_iv); }nla_nest_end (nl_msg, key_dec); -nla_nest_end (nl_msg, attr); +nla_nest_end (nl_msg, key_conf); + ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -647,18 +662,18 @@msg (D_DCO_DEBUG ,"%s: peer-id %d, keepalive %d/%d, mss %d" , __func__, peerid, keepalive_interval, keepalive_timeout, mss); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_SET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_SET );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_SET_PEER ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_PEER_ID , peerid); -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_KEEPALIVE_INTERVAL , +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_KEEPALIVE_INTERVAL , keepalive_interval); -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_KEEPALIVE_TIMEOUT , +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_KEEPALIVE_TIMEOUT , keepalive_timeout);nla_nest_end (nl_msg, attr);
@@ -707,7 +722,7 @@ }if (strncmp (nla_data (tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME ]), -OVPN_NL_MULTICAST_GROUP_PEERS , +OVPN_MCGRP_PEERS ,nla_len (tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME ])) !=0 ) {continue ;
@@ -720,7 +735,7 @@ }/** * Lookup the multicast id for OpenVPN. This method and its help method currently -* hardcode the lookup to OVPN_NL_NAME and OVPN_NL_MULTICAST_GROUP_PEERS but +* hardcode the lookup to OVPN_FAMILY_NAME and OVPN_MCGRP_PEERS but * extended in the future if we need to lookup more than one mcast id. */ static int
@@ -741,7 +756,7 @@genlmsg_put (nl_msg,0 ,0 , ctrlid,0 ,0 ,CTRL_CMD_GETFAMILY ,0 );int ret = -EMSGSIZE ; -NLA_PUT_STRING (nl_msg,CTRL_ATTR_FAMILY_NAME ,OVPN_NL_NAME ); +NLA_PUT_STRING (nl_msg,CTRL_ATTR_FAMILY_NAME ,OVPN_FAMILY_NAME ); ret =ovpn_nl_msg_send (dco, nl_msg, mcast_family_handler, dco, __func__);
@@ -757,38 +772,38 @@dco_context_t *dco = arg;struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg)); -struct nlattr *attrs[OVPN_ATTR_MAX +1 ]; +struct nlattr *attrs[OVPN_A_MAX +1 ];struct nlmsghdr *nlh =nlmsg_hdr (msg);if (!genlmsg_valid_hdr (nlh,0 )) {msg (D_DCO ,"ovpn-dco: invalid header" ); -return NL_SKIP ; +return NL_STOP ; } -if (nla_parse (attrs,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +if (nla_parse (attrs,OVPN_A_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL )) {msg (D_DCO ,"received bogus data from ovpn-dco" ); -return NL_SKIP ; +return NL_STOP ; }/* we must know which interface this message is referring to in order to * avoid mixing messages for other instances */ -if (!attrs[OVPN_ATTR_IFINDEX ]) +if (!attrs[OVPN_A_IFINDEX ]) {msg (D_DCO ,"ovpn-dco: Received message without ifindex" ); -return NL_SKIP ; +return NL_STOP ; } -uint32_t ifindex =nla_get_u32 (attrs[OVPN_ATTR_IFINDEX ]); +uint32_t ifindex =nla_get_u32 (attrs[OVPN_A_IFINDEX ]);if (ifindex != dco->ifindex) {msg (D_DCO_DEBUG ,"ovpn-dco: ignoring message (type=%d) for foreign ifindex %d" , gnlh->cmd, ifindex); -return NL_SKIP ; +return NL_STOP ; }/* based on the message type, we parse the subobject contained in the
@@ -800,48 +815,85 @@*/ switch (gnlh->cmd) { -case OVPN_CMD_DEL_PEER : +case OVPN_CMD_PEER_DEL_NTF : { -if (!attrs[OVPN_ATTR_DEL_PEER ]) +if (!attrs[OVPN_A_PEER ]) { -msg (D_DCO ,"ovpn-dco: no attributes in OVPN_DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no peer in PEER_DEL_NTF message" ); +return NL_STOP ; } -struct nlattr *dp_attrs[OVPN_DEL_PEER_ATTR_MAX +1 ]; -if (nla_parse_nested (dp_attrs,OVPN_DEL_PEER_ATTR_MAX , - attrs[OVPN_ATTR_DEL_PEER ],NULL )) +struct nlattr *dp_attrs[OVPN_A_PEER_MAX +1 ]; +if (nla_parse_nested (dp_attrs,OVPN_A_PEER_MAX , attrs[OVPN_A_PEER ], +NULL )) { -msg (D_DCO ,"received bogus del peer packet data from ovpn-dco" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: can't parse peer in PEER_DEL_NTF messsage" ); +return NL_STOP ; } -if (!dp_attrs[OVPN_DEL_PEER_ATTR_REASON ]) +if (!dp_attrs[OVPN_A_PEER_DEL_REASON ]) { -msg (D_DCO ,"ovpn-dco: no reason in DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no reason in PEER_DEL_NTF message" ); +return NL_STOP ; } -if (!dp_attrs[OVPN_DEL_PEER_ATTR_PEER_ID ]) +if (!dp_attrs[OVPN_A_PEER_ID ]) { -msg (D_DCO ,"ovpn-dco: no peer-id in DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no peer-id in PEER_DEL_NTF message" ); +return NL_STOP ; } -int reason =nla_get_u8 (dp_attrs[OVPN_DEL_PEER_ATTR_REASON ]); -unsigned int peerid =nla_get_u32 (dp_attrs[OVPN_DEL_PEER_ATTR_PEER_ID ]); -msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_DEL_PEER, ifindex: %d, peer-id %d, reason: %d" , +int reason =nla_get_u32 (dp_attrs[OVPN_A_PEER_DEL_REASON ]); +unsigned int peerid =nla_get_u32 (dp_attrs[OVPN_A_PEER_ID ]); + +msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_PEER_DEL_NTF, ifindex: %d, peer-id %u, reason: %d" , ifindex, peerid, reason); dco->dco_message_peer_id = peerid; dco->dco_del_peer_reason = reason; - dco->dco_message_type =OVPN_CMD_DEL_PEER ; + dco->dco_message_type =OVPN_CMD_PEER_DEL_NTF ; +break ; + } +case OVPN_CMD_KEY_SWAP_NTF : + { +if (!attrs[OVPN_A_KEYCONF ]) + { +msg (D_DCO ,"ovpn-dco: no keyconf in KEY_SWAP_NTF message" ); +return NL_STOP ; + } + +struct nlattr *dp_attrs[OVPN_A_KEYCONF_MAX +1 ]; +if (nla_parse_nested (dp_attrs,OVPN_A_KEYCONF_MAX , + attrs[OVPN_A_KEYCONF ],NULL )) + { +msg (D_DCO ,"ovpn-dco: can't parse keyconf in KEY_SWAP_NTF message" ); +return NL_STOP ; + } +if (!dp_attrs[OVPN_A_KEYCONF_PEER_ID ]) + { +msg (D_DCO ,"ovpn-dco: no peer-id in KEY_SWAP_NTF message" ); +return NL_STOP ; + } +if (!dp_attrs[OVPN_A_KEYCONF_KEY_ID ]) + { +msg (D_DCO ,"ovpn-dco: no key-id in KEY_SWAP_NTF message" ); +return NL_STOP ; + } + +int key_id =nla_get_u16 (dp_attrs[OVPN_A_KEYCONF_KEY_ID ]); +unsigned int peer_id =nla_get_u32 (dp_attrs[OVPN_A_KEYCONF_PEER_ID ]); + +msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_KEY_SWAP_NTF, ifindex: %d, peer-id %u, key-id: %d" , + ifindex, peer_id, key_id); + dco->dco_message_peer_id = peer_id; + dco->dco_message_key_id = key_id; + dco->dco_message_type =OVPN_CMD_KEY_SWAP_NTF ;break ; }default :msg (D_DCO ,"ovpn-dco: received unknown command: %d" , gnlh->cmd); dco->dco_message_type =0 ; -return NL_SKIP ; +return NL_STOP ; }return NL_OK ;
@@ -859,9 +911,9 @@static void dco_update_peer_stat (struct context_2 *c2,struct nlattr *tb[],uint32_t id) { -if (tb[OVPN_GET_PEER_RESP_ATTR_LINK_RX_BYTES ]) +if (tb[OVPN_A_PEER_LINK_RX_BYTES ]) { - c2->dco_read_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_LINK_RX_BYTES ]); + c2->dco_read_bytes =nla_get_u64 (tb[OVPN_A_PEER_LINK_RX_BYTES ]);msg (D_DCO_DEBUG ,"%s / dco_read_bytes: " counter_format, __func__, c2->dco_read_bytes); }
@@ -871,9 +923,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_LINK_TX_BYTES ]) +if (tb[OVPN_A_PEER_LINK_TX_BYTES ]) { - c2->dco_write_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_LINK_TX_BYTES ]); + c2->dco_write_bytes =nla_get_u64 (tb[OVPN_A_PEER_LINK_TX_BYTES ]);msg (D_DCO_DEBUG ,"%s / dco_write_bytes: " counter_format, __func__, c2->dco_write_bytes); }
@@ -883,9 +935,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_VPN_RX_BYTES ]) +if (tb[OVPN_A_PEER_VPN_RX_BYTES ]) { - c2->tun_read_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_VPN_RX_BYTES ]); + c2->tun_read_bytes =nla_get_u64 (tb[OVPN_A_PEER_VPN_RX_BYTES ]);msg (D_DCO_DEBUG ,"%s / tun_read_bytes: " counter_format, __func__, c2->tun_read_bytes); }
@@ -895,9 +947,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_VPN_TX_BYTES ]) +if (tb[OVPN_A_PEER_VPN_TX_BYTES ]) { - c2->tun_write_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_VPN_TX_BYTES ]); + c2->tun_write_bytes =nla_get_u64 (tb[OVPN_A_PEER_VPN_TX_BYTES ]);msg (D_DCO_DEBUG ,"%s / tun_write_bytes: " counter_format, __func__, c2->tun_write_bytes); }
@@ -911,33 +963,30 @@int dco_parse_peer_multi (struct nl_msg *msg,void *arg) { -struct nlattr *tb[OVPN_ATTR_MAX +1 ]; +struct nlattr *tb[OVPN_A_MAX +1 ];struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg));msg (D_DCO_DEBUG ,"%s: parsing message..." , __func__); -nla_parse (tb,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +nla_parse (tb,OVPN_A_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL ); -if (!tb[OVPN_ATTR_GET_PEER ]) +if (!tb[OVPN_A_PEER ]) {return NL_SKIP ; } -struct nlattr *tb_peer[OVPN_GET_PEER_RESP_ATTR_MAX +1 ]; +struct nlattr *tb_peer[OVPN_A_PEER_MAX +1 ]; +nla_parse_nested (tb_peer,OVPN_A_PEER_MAX , tb[OVPN_A_PEER ],NULL ); -nla_parse (tb_peer,OVPN_GET_PEER_RESP_ATTR_MAX , -nla_data (tb[OVPN_ATTR_GET_PEER ]), -nla_len (tb[OVPN_ATTR_GET_PEER ]),NULL ); - -if (!tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]) +if (!tb_peer[OVPN_A_PEER_ID ]) {msg (M_WARN ,"%s: no peer-id provided in reply" , __func__);return NL_SKIP ; }struct multi_context *m = arg; -uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]); +uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_A_PEER_ID ]);if (peer_id >= m->max_clients || !m->instances[peer_id]) {
@@ -957,7 +1006,7 @@ {msg (D_DCO_DEBUG ,"%s" , __func__); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_GET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_GET );nlmsg_hdr (nl_msg)->nlmsg_flags |=NLM_F_DUMP ;
@@ -979,33 +1028,33 @@ dco_parse_peer(struct nl_msg *msg, void *arg) { struct context *c = arg; -struct nlattr *tb[OVPN_ATTR_MAX +1 ]; +struct nlattr *tb[OVPN_A_MAX ];struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg));msg (D_DCO_DEBUG ,"%s: parsing message..." , __func__); -nla_parse (tb,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +nla_parse (tb,OVPN_A_PEER_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL ); -if (!tb[OVPN_ATTR_GET_PEER ]) +if (!tb[OVPN_A_PEER ]) {msg (D_DCO_DEBUG ,"%s: malformed reply" , __func__);return NL_SKIP ; } -struct nlattr *tb_peer[OVPN_GET_PEER_RESP_ATTR_MAX +1 ]; +struct nlattr *tb_peer[OVPN_A_PEER_MAX +1 ]; -nla_parse (tb_peer,OVPN_GET_PEER_RESP_ATTR_MAX , -nla_data (tb[OVPN_ATTR_GET_PEER ]), -nla_len (tb[OVPN_ATTR_GET_PEER ]),NULL ); +nla_parse (tb_peer,OVPN_A_PEER , +nla_data (tb[OVPN_A_PEER ]), +nla_len (tb[OVPN_A_PEER ]),NULL ); -if (!tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]) +if (!tb_peer[OVPN_A_PEER_ID ]) {msg (M_WARN ,"%s: no peer-id provided in reply" , __func__);return NL_SKIP ; } -uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]); +uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_A_PEER_ID ]);if (c->c2.tls_multi->dco_peer_id != peer_id) {return NL_SKIP ;
@@ -1033,11 +1082,11 @@ }dco_context_t *dco = &c->c1.tuntap->dco; -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_GET_PEER ); -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_GET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_GET ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_GET_PEER_ATTR_PEER_ID , peer_id); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peer_id);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg, dco_parse_peer, c, __func__);
src/openvpn/dco_linux.h +19 -0
@@ -31,9 +31,27 @@#include <netlink/socket.h> #include <netlink/netlink.h> +/* Defines to avoid mismatching with other platforms */ +#define OVPN_CMD_DEL_PEER OVPN_CMD_PEER_DEL_NTF +#define OVPN_CMD_SWAP_KEYS OVPN_CMD_KEY_SWAP_NTF +typedef enum ovpn_key_slot dco_key_slot_t ;typedef enum ovpn_cipher_alg dco_cipher_t ; +/* OVPN section */ + +enum ovpn_mode { +OVPN_MODE_P2P , +OVPN_MODE_MP , +}; + +enum ovpn_ifla_attrs { +IFLA_OVPN_UNSPEC =0 , +IFLA_OVPN_MODE , + + __IFLA_OVPN_AFTER_LAST, +IFLA_OVPN_MAX = __IFLA_OVPN_AFTER_LAST -1 , +}; typedef struct {
@@ -50,6 +68,7 @@int dco_message_type;int dco_message_peer_id; +int dco_message_key_id;int dco_del_peer_reason;uint64_t dco_read_bytes;uint64_t dco_write_bytes;
src/openvpn/networking_sitnl.c +1 -1
@@ -1354,7 +1354,7 @@struct rtattr *linkinfo =SITNL_NEST (&req.n,sizeof (req),IFLA_LINKINFO );SITNL_ADDATTR (&req.n,sizeof (req),IFLA_INFO_KIND , type,strlen (type) +1 );#if defined(ENABLE_DCO ) -if (arg && (strcmp (type,"ovpn-dco" ) ==0 )) +if (arg && (strcmp (type,OVPN_FAMILY_NAME ) ==0 )) {dco_context_t *dco = arg;struct rtattr *data =SITNL_NEST (&req.n,sizeof (req),IFLA_INFO_DATA );
src/openvpn/ovpn_dco_linux.h +73 -220
329 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/941?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I009f4e7ad38636f1c0b78d267561194c2bb4c051
Gerrit-Change-Number: 941
Gerrit-PatchSet: 5
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset
[Openvpn-devel] [L] Change in openvpn[master]: dco_linux: Introduce new uAPIs
In reply to a message not in the archiveAttention is currently required from: cron2, flichtenheld, ordex, plaisthos.
its_Giaan has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/941?usp=email )
Change subject: dco_linux: Introduce new uAPIs
......................................................................
Patch Set 5:
(4 comments)
File src/openvpn/dco_linux.c:
http://gerrit.openvpn.net/c/openvpn/+/941/comment/42a3e9d5_a3241db0 :
PS4, Line 547: return -1;
Quoted 1 line
this change looks unneccessary?
Done
http://gerrit.openvpn.net/c/openvpn/+/941/comment/72dedff9_08f21440 :
PS4, Line 574: }
Quoted 1 line
same here... […]
Done
http://gerrit.openvpn.net/c/openvpn/+/941/comment/88df7038_9eb77ae3 :
PS4, Line 591: keyconf = nla_nest_start(nl_msg, OVPN_A_KEYCONF);
Quoted 1 line
why wrap differently, and not keep `struct nlattr *
nla_nest_start()... […]
Done
http://gerrit.openvpn.net/c/openvpn/+/941/comment/fd7c904e_d3273a61 :
PS4, Line 860: case OVPN_CMD_KEY_SWAP_NTF:
Quoted 1 line
what is
KEY_SWAP_NTF? That's a new thing :-)
The 'NTF' prefix indicates that the message comes from the kernel module. So we can distinguish between messages sent and received.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/941?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I009f4e7ad38636f1c0b78d267561194c2bb4c051
Gerrit-Change-Number: 941
Gerrit-PatchSet: 5
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Mon, 05 May 2025 07:22:29 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment
[Openvpn-devel] [L] Change in openvpn[master]: dco_linux: Introduce new uAPIs
In reply to a message not in the archiveAttention is currently required from: cron2, flichtenheld, ordex, plaisthos.
Hello cron2, flichtenheld, ordex, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/941?usp=email
to look at the new patch set (#6).
Change subject: dco_linux: Introduce new uAPIs
......................................................................
dco_linux: Introduce new uAPIs
This patch updates the dco userspace API to
support communication with the new in-kernel
driver.
The main change involves updating the enums
used for Netlink messages to match the
definitions expected by the kernel module.
---
M src/openvpn/dco_linux.c
M src/openvpn/dco_linux.h
M src/openvpn/networking_sitnl.c
M src/openvpn/ovpn_dco_linux.h
4 files changed, 249 insertions(+), 350 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/41/941/6
src/openvpn/dco_linux.c +156 -129
@@ -96,7 +96,7 @@ }set_cloexec (nl_socket_get_fd (nl_sock)); - ret =genl_ctrl_resolve (nl_sock,OVPN_NL_NAME ); + ret =genl_ctrl_resolve (nl_sock,OVPN_FAMILY_NAME );if (ret <0 ) { msg(msglevel, "Cannot find ovpn_dco netlink component: %s",
@@ -109,7 +109,7 @@ }static struct nl_msg * -ovpn_dco_nlmsg_create (dco_context_t *dco,enum ovpn_nl_commands cmd) +ovpn_dco_nlmsg_create (dco_context_t *dco,int cmd) {struct nl_msg *nl_msg =nlmsg_alloc ();if (!nl_msg)
@@ -119,7 +119,7 @@ }genlmsg_put (nl_msg,0 ,0 , dco->ovpn_dco_id,0 ,0 , cmd,0 ); -NLA_PUT_U32 (nl_msg,OVPN_ATTR_IFINDEX , dco->ifindex); +NLA_PUT_U32 (nl_msg,OVPN_A_IFINDEX , dco->ifindex);return nl_msg; nla_put_failure:
@@ -231,20 +231,31 @@msg (D_DCO_DEBUG ,"%s: peer-id %d, fd %d, remote addr: %s" , __func__, peerid, sd, remotestr); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_NEW_PEER ); -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_NEW_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_NEW ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_PEER_ID , peerid); -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_SOCKET , sd); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_SOCKET , sd);/* Set the remote endpoint if defined (for UDP) */ if (remoteaddr) { remoteaddr =mapped_v4_to_v6 (remoteaddr, &gc); -int alen =af_addr_size (remoteaddr->sa_family); -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_SOCKADDR_REMOTE , alen, remoteaddr); +if (remoteaddr->sa_family ==AF_INET ) + { +NLA_PUT (nl_msg,OVPN_A_PEER_REMOTE_IPV4 ,sizeof (struct in_addr ), + &((struct sockaddr_in *)remoteaddr)->sin_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_REMOTE_PORT , ((struct sockaddr_in *)remoteaddr)->sin_port); + } +else if (remoteaddr->sa_family ==AF_INET6 ) + { +NLA_PUT (nl_msg,OVPN_A_PEER_REMOTE_IPV6 ,sizeof (struct in6_addr ), + &((struct sockaddr_in6 *)remoteaddr)->sin6_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_REMOTE_PORT , ((struct sockaddr_in6 *)remoteaddr)->sin6_port); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_REMOTE_IPV6_SCOPE_ID , ((struct sockaddr_in6 *)remoteaddr)->sin6_scope_id); + } }if (localaddr)
@@ -252,24 +263,26 @@ localaddr =mapped_v4_to_v6 (localaddr, &gc);if (localaddr->sa_family ==AF_INET ) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_LOCAL_IP ,sizeof (struct in_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_LOCAL_IPV4 ,sizeof (struct in_addr ), &((struct sockaddr_in *)localaddr)->sin_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_LOCAL_PORT , ((struct sockaddr_in *)localaddr)->sin_port); }else if (localaddr->sa_family ==AF_INET6 ) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_LOCAL_IP ,sizeof (struct in6_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_LOCAL_IPV6 ,sizeof (struct in6_addr ), &((struct sockaddr_in6 *)localaddr)->sin6_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_LOCAL_PORT , ((struct sockaddr_in6 *)localaddr)->sin6_port); } }/* Set the primary VPN IP addresses of the peer */ if (vpn_ipv4) { -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_IPV4 , vpn_ipv4->s_addr); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_VPN_IPV4 , vpn_ipv4->s_addr); }if (vpn_ipv6) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_IPV6 ,sizeof (struct in6_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_VPN_IPV6 ,sizeof (struct in6_addr ), vpn_ipv6); }nla_nest_end (nl_msg, attr);
@@ -481,7 +494,7 @@msg (D_DCO_DEBUG ,"%s: %s" , __func__, dev);ASSERT (tt->type ==DEV_TYPE_TUN ); -int ret =net_iface_new (ctx, dev,"ovpn-dco" , &tt->dco); +int ret =net_iface_new (ctx, dev,OVPN_FAMILY_NAME , &tt->dco);if (ret <0 ) {msg (D_DCO_DEBUG ,"Cannot create DCO interface %s: %d" , dev, ret);
@@ -515,15 +528,15 @@ {msg (D_DCO_DEBUG ,"%s: peer-id %d" , __func__, peerid); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_SWAP_KEYS ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_SWAP );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_SWAP_KEYS ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_KEYCONF );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_SWAP_KEYS_ATTR_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -539,15 +552,15 @@ {msg (D_DCO_DEBUG ,"%s: peer-id %d" , __func__, peerid); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_DEL_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_DEL );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_DEL_PEER ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_DEL_PEER_ATTR_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -562,19 +575,19 @@ dco_del_key(dco_context_t *dco, unsigned int peerid, dco_key_slot_t slot) { +int ret = -EMSGSIZE ;msg (D_DCO_DEBUG ,"%s: peer-id %d, slot %d" , __func__, peerid, slot); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_DEL_KEY ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_DEL );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_DEL_KEY ); -int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_DEL_KEY_ATTR_PEER_ID , peerid); -NLA_PUT_U8 (nl_msg,OVPN_DEL_KEY_ATTR_KEY_SLOT , slot); -nla_nest_end (nl_msg, attr); +struct nlattr *keyconf =nla_nest_start (nl_msg,OVPN_A_KEYCONF ); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_SLOT , slot); +nla_nest_end (nl_msg, keyconf); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -596,7 +609,7 @@const size_t key_len =cipher_kt_key_size (ciphername);const int nonce_tail_len =8 ; -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_NEW_KEY ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_NEW );if (!nl_msg) {return -ENOMEM ;
@@ -605,33 +618,35 @@dco_cipher_t dco_cipher =dco_get_cipher (ciphername);int ret = -EMSGSIZE ; -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_NEW_KEY ); -NLA_PUT_U32 (nl_msg,OVPN_NEW_KEY_ATTR_PEER_ID , peerid); -NLA_PUT_U8 (nl_msg,OVPN_NEW_KEY_ATTR_KEY_SLOT , slot); -NLA_PUT_U8 (nl_msg,OVPN_NEW_KEY_ATTR_KEY_ID , keyid); -NLA_PUT_U16 (nl_msg,OVPN_NEW_KEY_ATTR_CIPHER_ALG , dco_cipher); + +struct nlattr *key_conf =nla_nest_start (nl_msg,OVPN_A_KEYCONF ); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_SLOT , slot); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_KEY_ID , keyid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_CIPHER_ALG , dco_cipher);struct nlattr *key_enc =nla_nest_start (nl_msg, -OVPN_NEW_KEY_ATTR_ENCRYPT_KEY ); +OVPN_A_KEYCONF_ENCRYPT_DIR );if (dco_cipher !=OVPN_CIPHER_ALG_NONE ) { -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_CIPHER_KEY , key_len, encrypt_key); -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_NONCE_TAIL , nonce_tail_len, +NLA_PUT (nl_msg,OVPN_A_KEYDIR_CIPHER_KEY , key_len, encrypt_key); +NLA_PUT (nl_msg,OVPN_A_KEYDIR_NONCE_TAIL , nonce_tail_len, encrypt_iv); }nla_nest_end (nl_msg, key_enc);struct nlattr *key_dec =nla_nest_start (nl_msg, -OVPN_NEW_KEY_ATTR_DECRYPT_KEY ); +OVPN_A_KEYCONF_DECRYPT_DIR );if (dco_cipher !=OVPN_CIPHER_ALG_NONE ) { -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_CIPHER_KEY , key_len, decrypt_key); -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_NONCE_TAIL , nonce_tail_len, +NLA_PUT (nl_msg,OVPN_A_KEYDIR_CIPHER_KEY , key_len, decrypt_key); +NLA_PUT (nl_msg,OVPN_A_KEYDIR_NONCE_TAIL , nonce_tail_len, decrypt_iv); }nla_nest_end (nl_msg, key_dec); -nla_nest_end (nl_msg, attr); +nla_nest_end (nl_msg, key_conf); + ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -647,18 +662,18 @@msg (D_DCO_DEBUG ,"%s: peer-id %d, keepalive %d/%d, mss %d" , __func__, peerid, keepalive_interval, keepalive_timeout, mss); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_SET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_SET );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_SET_PEER ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_PEER_ID , peerid); -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_KEEPALIVE_INTERVAL , +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_KEEPALIVE_INTERVAL , keepalive_interval); -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_KEEPALIVE_TIMEOUT , +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_KEEPALIVE_TIMEOUT , keepalive_timeout);nla_nest_end (nl_msg, attr);
@@ -707,7 +722,7 @@ }if (strncmp (nla_data (tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME ]), -OVPN_NL_MULTICAST_GROUP_PEERS , +OVPN_MCGRP_PEERS ,nla_len (tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME ])) !=0 ) {continue ;
@@ -720,7 +735,7 @@ }/** * Lookup the multicast id for OpenVPN. This method and its help method currently -* hardcode the lookup to OVPN_NL_NAME and OVPN_NL_MULTICAST_GROUP_PEERS but +* hardcode the lookup to OVPN_FAMILY_NAME and OVPN_MCGRP_PEERS but * extended in the future if we need to lookup more than one mcast id. */ static int
@@ -741,7 +756,7 @@genlmsg_put (nl_msg,0 ,0 , ctrlid,0 ,0 ,CTRL_CMD_GETFAMILY ,0 );int ret = -EMSGSIZE ; -NLA_PUT_STRING (nl_msg,CTRL_ATTR_FAMILY_NAME ,OVPN_NL_NAME ); +NLA_PUT_STRING (nl_msg,CTRL_ATTR_FAMILY_NAME ,OVPN_FAMILY_NAME ); ret =ovpn_nl_msg_send (dco, nl_msg, mcast_family_handler, dco, __func__);
@@ -757,38 +772,38 @@dco_context_t *dco = arg;struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg)); -struct nlattr *attrs[OVPN_ATTR_MAX +1 ]; +struct nlattr *attrs[OVPN_A_MAX +1 ];struct nlmsghdr *nlh =nlmsg_hdr (msg);if (!genlmsg_valid_hdr (nlh,0 )) {msg (D_DCO ,"ovpn-dco: invalid header" ); -return NL_SKIP ; +return NL_STOP ; } -if (nla_parse (attrs,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +if (nla_parse (attrs,OVPN_A_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL )) {msg (D_DCO ,"received bogus data from ovpn-dco" ); -return NL_SKIP ; +return NL_STOP ; }/* we must know which interface this message is referring to in order to * avoid mixing messages for other instances */ -if (!attrs[OVPN_ATTR_IFINDEX ]) +if (!attrs[OVPN_A_IFINDEX ]) {msg (D_DCO ,"ovpn-dco: Received message without ifindex" ); -return NL_SKIP ; +return NL_STOP ; } -uint32_t ifindex =nla_get_u32 (attrs[OVPN_ATTR_IFINDEX ]); +uint32_t ifindex =nla_get_u32 (attrs[OVPN_A_IFINDEX ]);if (ifindex != dco->ifindex) {msg (D_DCO_DEBUG ,"ovpn-dco: ignoring message (type=%d) for foreign ifindex %d" , gnlh->cmd, ifindex); -return NL_SKIP ; +return NL_STOP ; }/* based on the message type, we parse the subobject contained in the
@@ -800,48 +815,85 @@*/ switch (gnlh->cmd) { -case OVPN_CMD_DEL_PEER : +case OVPN_CMD_PEER_DEL_NTF : { -if (!attrs[OVPN_ATTR_DEL_PEER ]) +if (!attrs[OVPN_A_PEER ]) { -msg (D_DCO ,"ovpn-dco: no attributes in OVPN_DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no peer in PEER_DEL_NTF message" ); +return NL_STOP ; } -struct nlattr *dp_attrs[OVPN_DEL_PEER_ATTR_MAX +1 ]; -if (nla_parse_nested (dp_attrs,OVPN_DEL_PEER_ATTR_MAX , - attrs[OVPN_ATTR_DEL_PEER ],NULL )) +struct nlattr *dp_attrs[OVPN_A_PEER_MAX +1 ]; +if (nla_parse_nested (dp_attrs,OVPN_A_PEER_MAX , attrs[OVPN_A_PEER ], +NULL )) { -msg (D_DCO ,"received bogus del peer packet data from ovpn-dco" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: can't parse peer in PEER_DEL_NTF messsage" ); +return NL_STOP ; } -if (!dp_attrs[OVPN_DEL_PEER_ATTR_REASON ]) +if (!dp_attrs[OVPN_A_PEER_DEL_REASON ]) { -msg (D_DCO ,"ovpn-dco: no reason in DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no reason in PEER_DEL_NTF message" ); +return NL_STOP ; } -if (!dp_attrs[OVPN_DEL_PEER_ATTR_PEER_ID ]) +if (!dp_attrs[OVPN_A_PEER_ID ]) { -msg (D_DCO ,"ovpn-dco: no peer-id in DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no peer-id in PEER_DEL_NTF message" ); +return NL_STOP ; } -int reason =nla_get_u8 (dp_attrs[OVPN_DEL_PEER_ATTR_REASON ]); -unsigned int peerid =nla_get_u32 (dp_attrs[OVPN_DEL_PEER_ATTR_PEER_ID ]); -msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_DEL_PEER, ifindex: %d, peer-id %d, reason: %d" , +int reason =nla_get_u32 (dp_attrs[OVPN_A_PEER_DEL_REASON ]); +unsigned int peerid =nla_get_u32 (dp_attrs[OVPN_A_PEER_ID ]); + +msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_PEER_DEL_NTF, ifindex: %d, peer-id %u, reason: %d" , ifindex, peerid, reason); dco->dco_message_peer_id = peerid; dco->dco_del_peer_reason = reason; - dco->dco_message_type =OVPN_CMD_DEL_PEER ; + dco->dco_message_type =OVPN_CMD_PEER_DEL_NTF ; +break ; + } +case OVPN_CMD_KEY_SWAP_NTF : + { +if (!attrs[OVPN_A_KEYCONF ]) + { +msg (D_DCO ,"ovpn-dco: no keyconf in KEY_SWAP_NTF message" ); +return NL_STOP ; + } + +struct nlattr *dp_attrs[OVPN_A_KEYCONF_MAX +1 ]; +if (nla_parse_nested (dp_attrs,OVPN_A_KEYCONF_MAX , + attrs[OVPN_A_KEYCONF ],NULL )) + { +msg (D_DCO ,"ovpn-dco: can't parse keyconf in KEY_SWAP_NTF message" ); +return NL_STOP ; + } +if (!dp_attrs[OVPN_A_KEYCONF_PEER_ID ]) + { +msg (D_DCO ,"ovpn-dco: no peer-id in KEY_SWAP_NTF message" ); +return NL_STOP ; + } +if (!dp_attrs[OVPN_A_KEYCONF_KEY_ID ]) + { +msg (D_DCO ,"ovpn-dco: no key-id in KEY_SWAP_NTF message" ); +return NL_STOP ; + } + +int key_id =nla_get_u16 (dp_attrs[OVPN_A_KEYCONF_KEY_ID ]); +unsigned int peer_id =nla_get_u32 (dp_attrs[OVPN_A_KEYCONF_PEER_ID ]); + +msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_KEY_SWAP_NTF, ifindex: %d, peer-id %u, key-id: %d" , + ifindex, peer_id, key_id); + dco->dco_message_peer_id = peer_id; + dco->dco_message_key_id = key_id; + dco->dco_message_type =OVPN_CMD_KEY_SWAP_NTF ;break ; }default :msg (D_DCO ,"ovpn-dco: received unknown command: %d" , gnlh->cmd); dco->dco_message_type =0 ; -return NL_SKIP ; +return NL_STOP ; }return NL_OK ;
@@ -859,9 +911,9 @@static void dco_update_peer_stat (struct context_2 *c2,struct nlattr *tb[],uint32_t id) { -if (tb[OVPN_GET_PEER_RESP_ATTR_LINK_RX_BYTES ]) +if (tb[OVPN_A_PEER_LINK_RX_BYTES ]) { - c2->dco_read_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_LINK_RX_BYTES ]); + c2->dco_read_bytes =nla_get_u64 (tb[OVPN_A_PEER_LINK_RX_BYTES ]);msg (D_DCO_DEBUG ,"%s / dco_read_bytes: " counter_format, __func__, c2->dco_read_bytes); }
@@ -871,9 +923,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_LINK_TX_BYTES ]) +if (tb[OVPN_A_PEER_LINK_TX_BYTES ]) { - c2->dco_write_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_LINK_TX_BYTES ]); + c2->dco_write_bytes =nla_get_u64 (tb[OVPN_A_PEER_LINK_TX_BYTES ]);msg (D_DCO_DEBUG ,"%s / dco_write_bytes: " counter_format, __func__, c2->dco_write_bytes); }
@@ -883,9 +935,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_VPN_RX_BYTES ]) +if (tb[OVPN_A_PEER_VPN_RX_BYTES ]) { - c2->tun_read_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_VPN_RX_BYTES ]); + c2->tun_read_bytes =nla_get_u64 (tb[OVPN_A_PEER_VPN_RX_BYTES ]);msg (D_DCO_DEBUG ,"%s / tun_read_bytes: " counter_format, __func__, c2->tun_read_bytes); }
@@ -895,9 +947,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_VPN_TX_BYTES ]) +if (tb[OVPN_A_PEER_VPN_TX_BYTES ]) { - c2->tun_write_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_VPN_TX_BYTES ]); + c2->tun_write_bytes =nla_get_u64 (tb[OVPN_A_PEER_VPN_TX_BYTES ]);msg (D_DCO_DEBUG ,"%s / tun_write_bytes: " counter_format, __func__, c2->tun_write_bytes); }
@@ -911,33 +963,30 @@int dco_parse_peer_multi (struct nl_msg *msg,void *arg) { -struct nlattr *tb[OVPN_ATTR_MAX +1 ]; +struct nlattr *tb[OVPN_A_MAX +1 ];struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg));msg (D_DCO_DEBUG ,"%s: parsing message..." , __func__); -nla_parse (tb,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +nla_parse (tb,OVPN_A_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL ); -if (!tb[OVPN_ATTR_GET_PEER ]) +if (!tb[OVPN_A_PEER ]) {return NL_SKIP ; } -struct nlattr *tb_peer[OVPN_GET_PEER_RESP_ATTR_MAX +1 ]; +struct nlattr *tb_peer[OVPN_A_PEER_MAX +1 ]; +nla_parse_nested (tb_peer,OVPN_A_PEER_MAX , tb[OVPN_A_PEER ],NULL ); -nla_parse (tb_peer,OVPN_GET_PEER_RESP_ATTR_MAX , -nla_data (tb[OVPN_ATTR_GET_PEER ]), -nla_len (tb[OVPN_ATTR_GET_PEER ]),NULL ); - -if (!tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]) +if (!tb_peer[OVPN_A_PEER_ID ]) {msg (M_WARN ,"%s: no peer-id provided in reply" , __func__);return NL_SKIP ; }struct multi_context *m = arg; -uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]); +uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_A_PEER_ID ]);if (peer_id >= m->max_clients || !m->instances[peer_id]) {
@@ -957,7 +1006,7 @@ {msg (D_DCO_DEBUG ,"%s" , __func__); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_GET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_GET );nlmsg_hdr (nl_msg)->nlmsg_flags |=NLM_F_DUMP ;
@@ -979,33 +1028,33 @@ dco_parse_peer(struct nl_msg *msg, void *arg) { struct context *c = arg; -struct nlattr *tb[OVPN_ATTR_MAX +1 ]; +struct nlattr *tb[OVPN_A_MAX ];struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg));msg (D_DCO_DEBUG ,"%s: parsing message..." , __func__); -nla_parse (tb,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +nla_parse (tb,OVPN_A_PEER_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL ); -if (!tb[OVPN_ATTR_GET_PEER ]) +if (!tb[OVPN_A_PEER ]) {msg (D_DCO_DEBUG ,"%s: malformed reply" , __func__);return NL_SKIP ; } -struct nlattr *tb_peer[OVPN_GET_PEER_RESP_ATTR_MAX +1 ]; +struct nlattr *tb_peer[OVPN_A_PEER_MAX +1 ]; -nla_parse (tb_peer,OVPN_GET_PEER_RESP_ATTR_MAX , -nla_data (tb[OVPN_ATTR_GET_PEER ]), -nla_len (tb[OVPN_ATTR_GET_PEER ]),NULL ); +nla_parse (tb_peer,OVPN_A_PEER , +nla_data (tb[OVPN_A_PEER ]), +nla_len (tb[OVPN_A_PEER ]),NULL ); -if (!tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]) +if (!tb_peer[OVPN_A_PEER_ID ]) {msg (M_WARN ,"%s: no peer-id provided in reply" , __func__);return NL_SKIP ; } -uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]); +uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_A_PEER_ID ]);if (c->c2.tls_multi->dco_peer_id != peer_id) {return NL_SKIP ;
@@ -1033,11 +1082,11 @@ }dco_context_t *dco = &c->c1.tuntap->dco; -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_GET_PEER ); -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_GET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_GET ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_GET_PEER_ATTR_PEER_ID , peer_id); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peer_id);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg, dco_parse_peer, c, __func__);
@@ -1071,29 +1120,7 @@const char *dco_version_string (struct gc_arena *gc) { -struct buffer out =alloc_buf_gc (256 , gc); -FILE *fp =fopen ("/sys/module/ovpn_dco_v2/version" ,"r" ); -if (!fp) - { -return "N/A" ; - } - -if (!fgets (BSTR (&out),BCAP (&out), fp)) - { -fclose (fp); -return "ERR" ; - } - -/* remove potential newline at the end of the string */ -char *str =BSTR (&out); -char *nl =strchr (str,'\n' ); -if (nl) - { - *nl ='\0' ; - } - -fclose (fp); -return BSTR (&out); +return "Unknown" ; }void
src/openvpn/dco_linux.h +19 -0
@@ -31,9 +31,27 @@#include <netlink/socket.h> #include <netlink/netlink.h> +/* Defines to avoid mismatching with other platforms */ +#define OVPN_CMD_DEL_PEER OVPN_CMD_PEER_DEL_NTF +#define OVPN_CMD_SWAP_KEYS OVPN_CMD_KEY_SWAP_NTF +typedef enum ovpn_key_slot dco_key_slot_t ;typedef enum ovpn_cipher_alg dco_cipher_t ; +/* OVPN section */ + +enum ovpn_mode { +OVPN_MODE_P2P , +OVPN_MODE_MP , +}; + +enum ovpn_ifla_attrs { +IFLA_OVPN_UNSPEC =0 , +IFLA_OVPN_MODE , + + __IFLA_OVPN_AFTER_LAST, +IFLA_OVPN_MAX = __IFLA_OVPN_AFTER_LAST -1 , +}; typedef struct {
@@ -50,6 +68,7 @@int dco_message_type;int dco_message_peer_id; +int dco_message_key_id;int dco_del_peer_reason;uint64_t dco_read_bytes;uint64_t dco_write_bytes;
src/openvpn/networking_sitnl.c +1 -1
@@ -1354,7 +1354,7 @@struct rtattr *linkinfo =SITNL_NEST (&req.n,sizeof (req),IFLA_LINKINFO );SITNL_ADDATTR (&req.n,sizeof (req),IFLA_INFO_KIND , type,strlen (type) +1 );#if defined(ENABLE_DCO ) -if (arg && (strcmp (type,"ovpn-dco" ) ==0 )) +if (arg && (strcmp (type,OVPN_FAMILY_NAME ) ==0 )) {dco_context_t *dco = arg;struct rtattr *data =SITNL_NEST (&req.n,sizeof (req),IFLA_INFO_DATA );
src/openvpn/ovpn_dco_linux.h +73 -220
329 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/941?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I009f4e7ad38636f1c0b78d267561194c2bb4c051
Gerrit-Change-Number: 941
Gerrit-PatchSet: 6
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-MessageType: newpatchset
[Openvpn-devel] [L] Change in openvpn[master]: dco_linux: Introduce new uAPIs
In reply to a message not in the archiveAttention is currently required from: flichtenheld, its_Giaan, ordex, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/941?usp=email )
Change subject: dco_linux: Introduce new uAPIs
......................................................................
Patch Set 6: Code-Review+2
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/941?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I009f4e7ad38636f1c0b78d267561194c2bb4c051
Gerrit-Change-Number: 941
Gerrit-PatchSet: 6
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Mon, 05 May 2025 08:52:36 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
PATCH v6 1/1 dco_linux: Introduce new uAPIs
In reply to a message not in the archiveFrom: Gianmarco De Gregori <[email protected]...>
This patch updates the dco userspace API to
support communication with the new in-kernel
driver.
The main change involves updating the enums
used for Netlink messages to match the
definitions expected by the kernel module.
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/941
This mail reflects revision 6 of this Change.
Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>
src/openvpn/dco_linux.c +156 -129
@@ -96,7 +96,7 @@ }set_cloexec (nl_socket_get_fd (nl_sock)); - ret =genl_ctrl_resolve (nl_sock,OVPN_NL_NAME ); + ret =genl_ctrl_resolve (nl_sock,OVPN_FAMILY_NAME );if (ret <0 ) { msg(msglevel, "Cannot find ovpn_dco netlink component: %s",
@@ -109,7 +109,7 @@ }static struct nl_msg * -ovpn_dco_nlmsg_create (dco_context_t *dco,enum ovpn_nl_commands cmd) +ovpn_dco_nlmsg_create (dco_context_t *dco,int cmd) {struct nl_msg *nl_msg =nlmsg_alloc ();if (!nl_msg)
@@ -119,7 +119,7 @@ }genlmsg_put (nl_msg,0 ,0 , dco->ovpn_dco_id,0 ,0 , cmd,0 ); -NLA_PUT_U32 (nl_msg,OVPN_ATTR_IFINDEX , dco->ifindex); +NLA_PUT_U32 (nl_msg,OVPN_A_IFINDEX , dco->ifindex);return nl_msg; nla_put_failure:
@@ -231,20 +231,31 @@msg (D_DCO_DEBUG ,"%s: peer-id %d, fd %d, remote addr: %s" , __func__, peerid, sd, remotestr); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_NEW_PEER ); -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_NEW_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_NEW ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_PEER_ID , peerid); -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_SOCKET , sd); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_SOCKET , sd);/* Set the remote endpoint if defined (for UDP) */ if (remoteaddr) { remoteaddr =mapped_v4_to_v6 (remoteaddr, &gc); -int alen =af_addr_size (remoteaddr->sa_family); -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_SOCKADDR_REMOTE , alen, remoteaddr); +if (remoteaddr->sa_family ==AF_INET ) + { +NLA_PUT (nl_msg,OVPN_A_PEER_REMOTE_IPV4 ,sizeof (struct in_addr ), + &((struct sockaddr_in *)remoteaddr)->sin_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_REMOTE_PORT , ((struct sockaddr_in *)remoteaddr)->sin_port); + } +else if (remoteaddr->sa_family ==AF_INET6 ) + { +NLA_PUT (nl_msg,OVPN_A_PEER_REMOTE_IPV6 ,sizeof (struct in6_addr ), + &((struct sockaddr_in6 *)remoteaddr)->sin6_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_REMOTE_PORT , ((struct sockaddr_in6 *)remoteaddr)->sin6_port); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_REMOTE_IPV6_SCOPE_ID , ((struct sockaddr_in6 *)remoteaddr)->sin6_scope_id); + } }if (localaddr)
@@ -252,24 +263,26 @@ localaddr =mapped_v4_to_v6 (localaddr, &gc);if (localaddr->sa_family ==AF_INET ) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_LOCAL_IP ,sizeof (struct in_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_LOCAL_IPV4 ,sizeof (struct in_addr ), &((struct sockaddr_in *)localaddr)->sin_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_LOCAL_PORT , ((struct sockaddr_in *)localaddr)->sin_port); }else if (localaddr->sa_family ==AF_INET6 ) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_LOCAL_IP ,sizeof (struct in6_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_LOCAL_IPV6 ,sizeof (struct in6_addr ), &((struct sockaddr_in6 *)localaddr)->sin6_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_LOCAL_PORT , ((struct sockaddr_in6 *)localaddr)->sin6_port); } }/* Set the primary VPN IP addresses of the peer */ if (vpn_ipv4) { -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_IPV4 , vpn_ipv4->s_addr); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_VPN_IPV4 , vpn_ipv4->s_addr); }if (vpn_ipv6) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_IPV6 ,sizeof (struct in6_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_VPN_IPV6 ,sizeof (struct in6_addr ), vpn_ipv6); }nla_nest_end (nl_msg, attr);
@@ -481,7 +494,7 @@msg (D_DCO_DEBUG ,"%s: %s" , __func__, dev);ASSERT (tt->type ==DEV_TYPE_TUN ); -int ret =net_iface_new (ctx, dev,"ovpn-dco" , &tt->dco); +int ret =net_iface_new (ctx, dev,OVPN_FAMILY_NAME , &tt->dco);if (ret <0 ) {msg (D_DCO_DEBUG ,"Cannot create DCO interface %s: %d" , dev, ret);
@@ -515,15 +528,15 @@ {msg (D_DCO_DEBUG ,"%s: peer-id %d" , __func__, peerid); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_SWAP_KEYS ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_SWAP );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_SWAP_KEYS ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_KEYCONF );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_SWAP_KEYS_ATTR_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -539,15 +552,15 @@ {msg (D_DCO_DEBUG ,"%s: peer-id %d" , __func__, peerid); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_DEL_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_DEL );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_DEL_PEER ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_DEL_PEER_ATTR_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -562,19 +575,19 @@ dco_del_key(dco_context_t *dco, unsigned int peerid, dco_key_slot_t slot) { +int ret = -EMSGSIZE ;msg (D_DCO_DEBUG ,"%s: peer-id %d, slot %d" , __func__, peerid, slot); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_DEL_KEY ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_DEL );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_DEL_KEY ); -int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_DEL_KEY_ATTR_PEER_ID , peerid); -NLA_PUT_U8 (nl_msg,OVPN_DEL_KEY_ATTR_KEY_SLOT , slot); -nla_nest_end (nl_msg, attr); +struct nlattr *keyconf =nla_nest_start (nl_msg,OVPN_A_KEYCONF ); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_SLOT , slot); +nla_nest_end (nl_msg, keyconf); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -596,7 +609,7 @@const size_t key_len =cipher_kt_key_size (ciphername);const int nonce_tail_len =8 ; -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_NEW_KEY ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_NEW );if (!nl_msg) {return -ENOMEM ;
@@ -605,33 +618,35 @@dco_cipher_t dco_cipher =dco_get_cipher (ciphername);int ret = -EMSGSIZE ; -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_NEW_KEY ); -NLA_PUT_U32 (nl_msg,OVPN_NEW_KEY_ATTR_PEER_ID , peerid); -NLA_PUT_U8 (nl_msg,OVPN_NEW_KEY_ATTR_KEY_SLOT , slot); -NLA_PUT_U8 (nl_msg,OVPN_NEW_KEY_ATTR_KEY_ID , keyid); -NLA_PUT_U16 (nl_msg,OVPN_NEW_KEY_ATTR_CIPHER_ALG , dco_cipher); + +struct nlattr *key_conf =nla_nest_start (nl_msg,OVPN_A_KEYCONF ); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_SLOT , slot); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_KEY_ID , keyid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_CIPHER_ALG , dco_cipher);struct nlattr *key_enc =nla_nest_start (nl_msg, -OVPN_NEW_KEY_ATTR_ENCRYPT_KEY ); +OVPN_A_KEYCONF_ENCRYPT_DIR );if (dco_cipher !=OVPN_CIPHER_ALG_NONE ) { -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_CIPHER_KEY , key_len, encrypt_key); -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_NONCE_TAIL , nonce_tail_len, +NLA_PUT (nl_msg,OVPN_A_KEYDIR_CIPHER_KEY , key_len, encrypt_key); +NLA_PUT (nl_msg,OVPN_A_KEYDIR_NONCE_TAIL , nonce_tail_len, encrypt_iv); }nla_nest_end (nl_msg, key_enc);struct nlattr *key_dec =nla_nest_start (nl_msg, -OVPN_NEW_KEY_ATTR_DECRYPT_KEY ); +OVPN_A_KEYCONF_DECRYPT_DIR );if (dco_cipher !=OVPN_CIPHER_ALG_NONE ) { -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_CIPHER_KEY , key_len, decrypt_key); -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_NONCE_TAIL , nonce_tail_len, +NLA_PUT (nl_msg,OVPN_A_KEYDIR_CIPHER_KEY , key_len, decrypt_key); +NLA_PUT (nl_msg,OVPN_A_KEYDIR_NONCE_TAIL , nonce_tail_len, decrypt_iv); }nla_nest_end (nl_msg, key_dec); -nla_nest_end (nl_msg, attr); +nla_nest_end (nl_msg, key_conf); + ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -647,18 +662,18 @@msg (D_DCO_DEBUG ,"%s: peer-id %d, keepalive %d/%d, mss %d" , __func__, peerid, keepalive_interval, keepalive_timeout, mss); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_SET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_SET );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_SET_PEER ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_PEER_ID , peerid); -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_KEEPALIVE_INTERVAL , +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_KEEPALIVE_INTERVAL , keepalive_interval); -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_KEEPALIVE_TIMEOUT , +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_KEEPALIVE_TIMEOUT , keepalive_timeout);nla_nest_end (nl_msg, attr);
@@ -707,7 +722,7 @@ }if (strncmp (nla_data (tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME ]), -OVPN_NL_MULTICAST_GROUP_PEERS , +OVPN_MCGRP_PEERS ,nla_len (tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME ])) !=0 ) {continue ;
@@ -720,7 +735,7 @@ }/** * Lookup the multicast id for OpenVPN. This method and its help method currently -* hardcode the lookup to OVPN_NL_NAME and OVPN_NL_MULTICAST_GROUP_PEERS but +* hardcode the lookup to OVPN_FAMILY_NAME and OVPN_MCGRP_PEERS but * extended in the future if we need to lookup more than one mcast id. */ static int
@@ -741,7 +756,7 @@genlmsg_put (nl_msg,0 ,0 , ctrlid,0 ,0 ,CTRL_CMD_GETFAMILY ,0 );int ret = -EMSGSIZE ; -NLA_PUT_STRING (nl_msg,CTRL_ATTR_FAMILY_NAME ,OVPN_NL_NAME ); +NLA_PUT_STRING (nl_msg,CTRL_ATTR_FAMILY_NAME ,OVPN_FAMILY_NAME ); ret =ovpn_nl_msg_send (dco, nl_msg, mcast_family_handler, dco, __func__);
@@ -757,38 +772,38 @@dco_context_t *dco = arg;struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg)); -struct nlattr *attrs[OVPN_ATTR_MAX +1 ]; +struct nlattr *attrs[OVPN_A_MAX +1 ];struct nlmsghdr *nlh =nlmsg_hdr (msg);if (!genlmsg_valid_hdr (nlh,0 )) {msg (D_DCO ,"ovpn-dco: invalid header" ); -return NL_SKIP ; +return NL_STOP ; } -if (nla_parse (attrs,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +if (nla_parse (attrs,OVPN_A_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL )) {msg (D_DCO ,"received bogus data from ovpn-dco" ); -return NL_SKIP ; +return NL_STOP ; }/* we must know which interface this message is referring to in order to * avoid mixing messages for other instances */ -if (!attrs[OVPN_ATTR_IFINDEX ]) +if (!attrs[OVPN_A_IFINDEX ]) {msg (D_DCO ,"ovpn-dco: Received message without ifindex" ); -return NL_SKIP ; +return NL_STOP ; } -uint32_t ifindex =nla_get_u32 (attrs[OVPN_ATTR_IFINDEX ]); +uint32_t ifindex =nla_get_u32 (attrs[OVPN_A_IFINDEX ]);if (ifindex != dco->ifindex) {msg (D_DCO_DEBUG ,"ovpn-dco: ignoring message (type=%d) for foreign ifindex %d" , gnlh->cmd, ifindex); -return NL_SKIP ; +return NL_STOP ; }/* based on the message type, we parse the subobject contained in the
@@ -800,48 +815,85 @@*/ switch (gnlh->cmd) { -case OVPN_CMD_DEL_PEER : +case OVPN_CMD_PEER_DEL_NTF : { -if (!attrs[OVPN_ATTR_DEL_PEER ]) +if (!attrs[OVPN_A_PEER ]) { -msg (D_DCO ,"ovpn-dco: no attributes in OVPN_DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no peer in PEER_DEL_NTF message" ); +return NL_STOP ; } -struct nlattr *dp_attrs[OVPN_DEL_PEER_ATTR_MAX +1 ]; -if (nla_parse_nested (dp_attrs,OVPN_DEL_PEER_ATTR_MAX , - attrs[OVPN_ATTR_DEL_PEER ],NULL )) +struct nlattr *dp_attrs[OVPN_A_PEER_MAX +1 ]; +if (nla_parse_nested (dp_attrs,OVPN_A_PEER_MAX , attrs[OVPN_A_PEER ], +NULL )) { -msg (D_DCO ,"received bogus del peer packet data from ovpn-dco" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: can't parse peer in PEER_DEL_NTF messsage" ); +return NL_STOP ; } -if (!dp_attrs[OVPN_DEL_PEER_ATTR_REASON ]) +if (!dp_attrs[OVPN_A_PEER_DEL_REASON ]) { -msg (D_DCO ,"ovpn-dco: no reason in DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no reason in PEER_DEL_NTF message" ); +return NL_STOP ; } -if (!dp_attrs[OVPN_DEL_PEER_ATTR_PEER_ID ]) +if (!dp_attrs[OVPN_A_PEER_ID ]) { -msg (D_DCO ,"ovpn-dco: no peer-id in DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no peer-id in PEER_DEL_NTF message" ); +return NL_STOP ; } -int reason =nla_get_u8 (dp_attrs[OVPN_DEL_PEER_ATTR_REASON ]); -unsigned int peerid =nla_get_u32 (dp_attrs[OVPN_DEL_PEER_ATTR_PEER_ID ]); -msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_DEL_PEER, ifindex: %d, peer-id %d, reason: %d" , +int reason =nla_get_u32 (dp_attrs[OVPN_A_PEER_DEL_REASON ]); +unsigned int peerid =nla_get_u32 (dp_attrs[OVPN_A_PEER_ID ]); + +msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_PEER_DEL_NTF, ifindex: %d, peer-id %u, reason: %d" , ifindex, peerid, reason); dco->dco_message_peer_id = peerid; dco->dco_del_peer_reason = reason; - dco->dco_message_type =OVPN_CMD_DEL_PEER ; + dco->dco_message_type =OVPN_CMD_PEER_DEL_NTF ; +break ; + } +case OVPN_CMD_KEY_SWAP_NTF : + { +if (!attrs[OVPN_A_KEYCONF ]) + { +msg (D_DCO ,"ovpn-dco: no keyconf in KEY_SWAP_NTF message" ); +return NL_STOP ; + } + +struct nlattr *dp_attrs[OVPN_A_KEYCONF_MAX +1 ]; +if (nla_parse_nested (dp_attrs,OVPN_A_KEYCONF_MAX , + attrs[OVPN_A_KEYCONF ],NULL )) + { +msg (D_DCO ,"ovpn-dco: can't parse keyconf in KEY_SWAP_NTF message" ); +return NL_STOP ; + } +if (!dp_attrs[OVPN_A_KEYCONF_PEER_ID ]) + { +msg (D_DCO ,"ovpn-dco: no peer-id in KEY_SWAP_NTF message" ); +return NL_STOP ; + } +if (!dp_attrs[OVPN_A_KEYCONF_KEY_ID ]) + { +msg (D_DCO ,"ovpn-dco: no key-id in KEY_SWAP_NTF message" ); +return NL_STOP ; + } + +int key_id =nla_get_u16 (dp_attrs[OVPN_A_KEYCONF_KEY_ID ]); +unsigned int peer_id =nla_get_u32 (dp_attrs[OVPN_A_KEYCONF_PEER_ID ]); + +msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_KEY_SWAP_NTF, ifindex: %d, peer-id %u, key-id: %d" , + ifindex, peer_id, key_id); + dco->dco_message_peer_id = peer_id; + dco->dco_message_key_id = key_id; + dco->dco_message_type =OVPN_CMD_KEY_SWAP_NTF ;break ; }default :msg (D_DCO ,"ovpn-dco: received unknown command: %d" , gnlh->cmd); dco->dco_message_type =0 ; -return NL_SKIP ; +return NL_STOP ; }return NL_OK ;
@@ -859,9 +911,9 @@static void dco_update_peer_stat (struct context_2 *c2,struct nlattr *tb[],uint32_t id) { -if (tb[OVPN_GET_PEER_RESP_ATTR_LINK_RX_BYTES ]) +if (tb[OVPN_A_PEER_LINK_RX_BYTES ]) { - c2->dco_read_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_LINK_RX_BYTES ]); + c2->dco_read_bytes =nla_get_u64 (tb[OVPN_A_PEER_LINK_RX_BYTES ]);msg (D_DCO_DEBUG ,"%s / dco_read_bytes: " counter_format, __func__, c2->dco_read_bytes); }
@@ -871,9 +923,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_LINK_TX_BYTES ]) +if (tb[OVPN_A_PEER_LINK_TX_BYTES ]) { - c2->dco_write_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_LINK_TX_BYTES ]); + c2->dco_write_bytes =nla_get_u64 (tb[OVPN_A_PEER_LINK_TX_BYTES ]);msg (D_DCO_DEBUG ,"%s / dco_write_bytes: " counter_format, __func__, c2->dco_write_bytes); }
@@ -883,9 +935,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_VPN_RX_BYTES ]) +if (tb[OVPN_A_PEER_VPN_RX_BYTES ]) { - c2->tun_read_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_VPN_RX_BYTES ]); + c2->tun_read_bytes =nla_get_u64 (tb[OVPN_A_PEER_VPN_RX_BYTES ]);msg (D_DCO_DEBUG ,"%s / tun_read_bytes: " counter_format, __func__, c2->tun_read_bytes); }
@@ -895,9 +947,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_VPN_TX_BYTES ]) +if (tb[OVPN_A_PEER_VPN_TX_BYTES ]) { - c2->tun_write_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_VPN_TX_BYTES ]); + c2->tun_write_bytes =nla_get_u64 (tb[OVPN_A_PEER_VPN_TX_BYTES ]);msg (D_DCO_DEBUG ,"%s / tun_write_bytes: " counter_format, __func__, c2->tun_write_bytes); }
@@ -911,33 +963,30 @@int dco_parse_peer_multi (struct nl_msg *msg,void *arg) { -struct nlattr *tb[OVPN_ATTR_MAX +1 ]; +struct nlattr *tb[OVPN_A_MAX +1 ];struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg));msg (D_DCO_DEBUG ,"%s: parsing message..." , __func__); -nla_parse (tb,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +nla_parse (tb,OVPN_A_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL ); -if (!tb[OVPN_ATTR_GET_PEER ]) +if (!tb[OVPN_A_PEER ]) {return NL_SKIP ; } -struct nlattr *tb_peer[OVPN_GET_PEER_RESP_ATTR_MAX +1 ]; +struct nlattr *tb_peer[OVPN_A_PEER_MAX +1 ]; +nla_parse_nested (tb_peer,OVPN_A_PEER_MAX , tb[OVPN_A_PEER ],NULL ); -nla_parse (tb_peer,OVPN_GET_PEER_RESP_ATTR_MAX , -nla_data (tb[OVPN_ATTR_GET_PEER ]), -nla_len (tb[OVPN_ATTR_GET_PEER ]),NULL ); - -if (!tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]) +if (!tb_peer[OVPN_A_PEER_ID ]) {msg (M_WARN ,"%s: no peer-id provided in reply" , __func__);return NL_SKIP ; }struct multi_context *m = arg; -uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]); +uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_A_PEER_ID ]);if (peer_id >= m->max_clients || !m->instances[peer_id]) {
@@ -957,7 +1006,7 @@ {msg (D_DCO_DEBUG ,"%s" , __func__); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_GET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_GET );nlmsg_hdr (nl_msg)->nlmsg_flags |=NLM_F_DUMP ;
@@ -979,33 +1028,33 @@ dco_parse_peer(struct nl_msg *msg, void *arg) { struct context *c = arg; -struct nlattr *tb[OVPN_ATTR_MAX +1 ]; +struct nlattr *tb[OVPN_A_MAX ];struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg));msg (D_DCO_DEBUG ,"%s: parsing message..." , __func__); -nla_parse (tb,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +nla_parse (tb,OVPN_A_PEER_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL ); -if (!tb[OVPN_ATTR_GET_PEER ]) +if (!tb[OVPN_A_PEER ]) {msg (D_DCO_DEBUG ,"%s: malformed reply" , __func__);return NL_SKIP ; } -struct nlattr *tb_peer[OVPN_GET_PEER_RESP_ATTR_MAX +1 ]; +struct nlattr *tb_peer[OVPN_A_PEER_MAX +1 ]; -nla_parse (tb_peer,OVPN_GET_PEER_RESP_ATTR_MAX , -nla_data (tb[OVPN_ATTR_GET_PEER ]), -nla_len (tb[OVPN_ATTR_GET_PEER ]),NULL ); +nla_parse (tb_peer,OVPN_A_PEER , +nla_data (tb[OVPN_A_PEER ]), +nla_len (tb[OVPN_A_PEER ]),NULL ); -if (!tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]) +if (!tb_peer[OVPN_A_PEER_ID ]) {msg (M_WARN ,"%s: no peer-id provided in reply" , __func__);return NL_SKIP ; } -uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]); +uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_A_PEER_ID ]);if (c->c2.tls_multi->dco_peer_id != peer_id) {return NL_SKIP ;
@@ -1033,11 +1082,11 @@ }dco_context_t *dco = &c->c1.tuntap->dco; -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_GET_PEER ); -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_GET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_GET ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_GET_PEER_ATTR_PEER_ID , peer_id); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peer_id);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg, dco_parse_peer, c, __func__);
@@ -1071,29 +1120,7 @@const char *dco_version_string (struct gc_arena *gc) { -struct buffer out =alloc_buf_gc (256 , gc); -FILE *fp =fopen ("/sys/module/ovpn_dco_v2/version" ,"r" ); -if (!fp) - { -return "N/A" ; - } - -if (!fgets (BSTR (&out),BCAP (&out), fp)) - { -fclose (fp); -return "ERR" ; - } - -/* remove potential newline at the end of the string */ -char *str =BSTR (&out); -char *nl =strchr (str,'\n' ); -if (nl) - { - *nl ='\0' ; - } - -fclose (fp); -return BSTR (&out); +return "Unknown" ; }void
src/openvpn/dco_linux.h +19 -0
@@ -31,9 +31,27 @@#include <netlink/socket.h> #include <netlink/netlink.h> +/* Defines to avoid mismatching with other platforms */ +#define OVPN_CMD_DEL_PEER OVPN_CMD_PEER_DEL_NTF +#define OVPN_CMD_SWAP_KEYS OVPN_CMD_KEY_SWAP_NTF +typedef enum ovpn_key_slot dco_key_slot_t ;typedef enum ovpn_cipher_alg dco_cipher_t ; +/* OVPN section */ + +enum ovpn_mode { +OVPN_MODE_P2P , +OVPN_MODE_MP , +}; + +enum ovpn_ifla_attrs { +IFLA_OVPN_UNSPEC =0 , +IFLA_OVPN_MODE , + + __IFLA_OVPN_AFTER_LAST, +IFLA_OVPN_MAX = __IFLA_OVPN_AFTER_LAST -1 , +}; typedef struct {
@@ -50,6 +68,7 @@int dco_message_type;int dco_message_peer_id; +int dco_message_key_id;int dco_del_peer_reason;uint64_t dco_read_bytes;uint64_t dco_write_bytes;
src/openvpn/networking_sitnl.c +1 -1
@@ -1354,7 +1354,7 @@struct rtattr *linkinfo =SITNL_NEST (&req.n,sizeof (req),IFLA_LINKINFO );SITNL_ADDATTR (&req.n,sizeof (req),IFLA_INFO_KIND , type,strlen (type) +1 );#if defined(ENABLE_DCO ) -if (arg && (strcmp (type,"ovpn-dco" ) ==0 )) +if (arg && (strcmp (type,OVPN_FAMILY_NAME ) ==0 )) {dco_context_t *dco = arg;struct rtattr *data =SITNL_NEST (&req.n,sizeof (req),IFLA_INFO_DATA );
src/openvpn/ovpn_dco_linux.h +73 -220
329 lines not on this page · raw message
[Openvpn-devel] [PATCH applied] Re: dco_linux: Introduce new uAPIs
So, after quite a bit of discussion and a number of new issues opened against backport and dco-net-next :-) - *this* patch is fine, as in, client and server functionality work with the new in-kernel Linux DCO module now (tested via backport to Ubuntu 20.04).
There are some known issues left - the version number for the new module is not printed (infrastructure missing on the other side, and decisions need to be made) - and the kernel side is not playing nice with t_client/3000 byte yet. But this is not a userland issue, so we merge this and now can do more intensive testing with in-kernel DCO.
HEADS UP
- from now on, master/2.7 will only support "new Linux DCO" (module named "ovpn")
- 2.6.x will only ever support "old DCO" (module named "ovpn-dco-v2")
both kernel modules can coexist (different namespace), so Linux distribution maintainers can ship one or the other or both, to enable "the OpenVPN version that they ship" to use "DCO in the kernel that they ship".
Your patch has been applied to the master branch.
commit b736e3fa983ec3c3125f7ba77689132fcec39a00
Author: Gianmarco De Gregori Date: Mon May 5 10:57:14 2025 +0200
dco_linux: Introduce new uAPIs
Signed-off-by: Gianmarco De Gregori <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg31554.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
[Openvpn-devel] [L] Change in openvpn[master]: dco_linux: Introduce new uAPIs
In reply to a message not in the archivecron2 has uploaded a new patch set (#7) to the change originally created by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/941?usp=email )
The following approvals got outdated and were removed:
Code-Review+2 by cron2
Change subject: dco_linux: Introduce new uAPIs
......................................................................
dco_linux: Introduce new uAPIs
This patch updates the dco userspace API to
support communication with the new in-kernel
driver.
The main change involves updating the enums
used for Netlink messages to match the
definitions expected by the kernel module.
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg31554.html
---
M src/openvpn/dco_linux.c
M src/openvpn/dco_linux.h
M src/openvpn/networking_sitnl.c
M src/openvpn/ovpn_dco_linux.h
4 files changed, 249 insertions(+), 350 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/41/941/7
src/openvpn/dco_linux.c +156 -129
@@ -96,7 +96,7 @@ }set_cloexec (nl_socket_get_fd (nl_sock)); - ret =genl_ctrl_resolve (nl_sock,OVPN_NL_NAME ); + ret =genl_ctrl_resolve (nl_sock,OVPN_FAMILY_NAME );if (ret <0 ) { msg(msglevel, "Cannot find ovpn_dco netlink component: %s",
@@ -109,7 +109,7 @@ }static struct nl_msg * -ovpn_dco_nlmsg_create (dco_context_t *dco,enum ovpn_nl_commands cmd) +ovpn_dco_nlmsg_create (dco_context_t *dco,int cmd) {struct nl_msg *nl_msg =nlmsg_alloc ();if (!nl_msg)
@@ -119,7 +119,7 @@ }genlmsg_put (nl_msg,0 ,0 , dco->ovpn_dco_id,0 ,0 , cmd,0 ); -NLA_PUT_U32 (nl_msg,OVPN_ATTR_IFINDEX , dco->ifindex); +NLA_PUT_U32 (nl_msg,OVPN_A_IFINDEX , dco->ifindex);return nl_msg; nla_put_failure:
@@ -231,20 +231,31 @@msg (D_DCO_DEBUG ,"%s: peer-id %d, fd %d, remote addr: %s" , __func__, peerid, sd, remotestr); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_NEW_PEER ); -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_NEW_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_NEW ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_PEER_ID , peerid); -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_SOCKET , sd); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_SOCKET , sd);/* Set the remote endpoint if defined (for UDP) */ if (remoteaddr) { remoteaddr =mapped_v4_to_v6 (remoteaddr, &gc); -int alen =af_addr_size (remoteaddr->sa_family); -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_SOCKADDR_REMOTE , alen, remoteaddr); +if (remoteaddr->sa_family ==AF_INET ) + { +NLA_PUT (nl_msg,OVPN_A_PEER_REMOTE_IPV4 ,sizeof (struct in_addr ), + &((struct sockaddr_in *)remoteaddr)->sin_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_REMOTE_PORT , ((struct sockaddr_in *)remoteaddr)->sin_port); + } +else if (remoteaddr->sa_family ==AF_INET6 ) + { +NLA_PUT (nl_msg,OVPN_A_PEER_REMOTE_IPV6 ,sizeof (struct in6_addr ), + &((struct sockaddr_in6 *)remoteaddr)->sin6_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_REMOTE_PORT , ((struct sockaddr_in6 *)remoteaddr)->sin6_port); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_REMOTE_IPV6_SCOPE_ID , ((struct sockaddr_in6 *)remoteaddr)->sin6_scope_id); + } }if (localaddr)
@@ -252,24 +263,26 @@ localaddr =mapped_v4_to_v6 (localaddr, &gc);if (localaddr->sa_family ==AF_INET ) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_LOCAL_IP ,sizeof (struct in_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_LOCAL_IPV4 ,sizeof (struct in_addr ), &((struct sockaddr_in *)localaddr)->sin_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_LOCAL_PORT , ((struct sockaddr_in *)localaddr)->sin_port); }else if (localaddr->sa_family ==AF_INET6 ) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_LOCAL_IP ,sizeof (struct in6_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_LOCAL_IPV6 ,sizeof (struct in6_addr ), &((struct sockaddr_in6 *)localaddr)->sin6_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_LOCAL_PORT , ((struct sockaddr_in6 *)localaddr)->sin6_port); } }/* Set the primary VPN IP addresses of the peer */ if (vpn_ipv4) { -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_IPV4 , vpn_ipv4->s_addr); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_VPN_IPV4 , vpn_ipv4->s_addr); }if (vpn_ipv6) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_IPV6 ,sizeof (struct in6_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_VPN_IPV6 ,sizeof (struct in6_addr ), vpn_ipv6); }nla_nest_end (nl_msg, attr);
@@ -481,7 +494,7 @@msg (D_DCO_DEBUG ,"%s: %s" , __func__, dev);ASSERT (tt->type ==DEV_TYPE_TUN ); -int ret =net_iface_new (ctx, dev,"ovpn-dco" , &tt->dco); +int ret =net_iface_new (ctx, dev,OVPN_FAMILY_NAME , &tt->dco);if (ret <0 ) {msg (D_DCO_DEBUG ,"Cannot create DCO interface %s: %d" , dev, ret);
@@ -515,15 +528,15 @@ {msg (D_DCO_DEBUG ,"%s: peer-id %d" , __func__, peerid); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_SWAP_KEYS ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_SWAP );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_SWAP_KEYS ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_KEYCONF );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_SWAP_KEYS_ATTR_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -539,15 +552,15 @@ {msg (D_DCO_DEBUG ,"%s: peer-id %d" , __func__, peerid); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_DEL_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_DEL );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_DEL_PEER ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_DEL_PEER_ATTR_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -562,19 +575,19 @@ dco_del_key(dco_context_t *dco, unsigned int peerid, dco_key_slot_t slot) { +int ret = -EMSGSIZE ;msg (D_DCO_DEBUG ,"%s: peer-id %d, slot %d" , __func__, peerid, slot); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_DEL_KEY ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_DEL );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_DEL_KEY ); -int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_DEL_KEY_ATTR_PEER_ID , peerid); -NLA_PUT_U8 (nl_msg,OVPN_DEL_KEY_ATTR_KEY_SLOT , slot); -nla_nest_end (nl_msg, attr); +struct nlattr *keyconf =nla_nest_start (nl_msg,OVPN_A_KEYCONF ); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_SLOT , slot); +nla_nest_end (nl_msg, keyconf); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -596,7 +609,7 @@const size_t key_len =cipher_kt_key_size (ciphername);const int nonce_tail_len =8 ; -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_NEW_KEY ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_NEW );if (!nl_msg) {return -ENOMEM ;
@@ -605,33 +618,35 @@dco_cipher_t dco_cipher =dco_get_cipher (ciphername);int ret = -EMSGSIZE ; -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_NEW_KEY ); -NLA_PUT_U32 (nl_msg,OVPN_NEW_KEY_ATTR_PEER_ID , peerid); -NLA_PUT_U8 (nl_msg,OVPN_NEW_KEY_ATTR_KEY_SLOT , slot); -NLA_PUT_U8 (nl_msg,OVPN_NEW_KEY_ATTR_KEY_ID , keyid); -NLA_PUT_U16 (nl_msg,OVPN_NEW_KEY_ATTR_CIPHER_ALG , dco_cipher); + +struct nlattr *key_conf =nla_nest_start (nl_msg,OVPN_A_KEYCONF ); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_SLOT , slot); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_KEY_ID , keyid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_CIPHER_ALG , dco_cipher);struct nlattr *key_enc =nla_nest_start (nl_msg, -OVPN_NEW_KEY_ATTR_ENCRYPT_KEY ); +OVPN_A_KEYCONF_ENCRYPT_DIR );if (dco_cipher !=OVPN_CIPHER_ALG_NONE ) { -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_CIPHER_KEY , key_len, encrypt_key); -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_NONCE_TAIL , nonce_tail_len, +NLA_PUT (nl_msg,OVPN_A_KEYDIR_CIPHER_KEY , key_len, encrypt_key); +NLA_PUT (nl_msg,OVPN_A_KEYDIR_NONCE_TAIL , nonce_tail_len, encrypt_iv); }nla_nest_end (nl_msg, key_enc);struct nlattr *key_dec =nla_nest_start (nl_msg, -OVPN_NEW_KEY_ATTR_DECRYPT_KEY ); +OVPN_A_KEYCONF_DECRYPT_DIR );if (dco_cipher !=OVPN_CIPHER_ALG_NONE ) { -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_CIPHER_KEY , key_len, decrypt_key); -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_NONCE_TAIL , nonce_tail_len, +NLA_PUT (nl_msg,OVPN_A_KEYDIR_CIPHER_KEY , key_len, decrypt_key); +NLA_PUT (nl_msg,OVPN_A_KEYDIR_NONCE_TAIL , nonce_tail_len, decrypt_iv); }nla_nest_end (nl_msg, key_dec); -nla_nest_end (nl_msg, attr); +nla_nest_end (nl_msg, key_conf); + ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -647,18 +662,18 @@msg (D_DCO_DEBUG ,"%s: peer-id %d, keepalive %d/%d, mss %d" , __func__, peerid, keepalive_interval, keepalive_timeout, mss); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_SET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_SET );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_SET_PEER ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_PEER_ID , peerid); -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_KEEPALIVE_INTERVAL , +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_KEEPALIVE_INTERVAL , keepalive_interval); -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_KEEPALIVE_TIMEOUT , +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_KEEPALIVE_TIMEOUT , keepalive_timeout);nla_nest_end (nl_msg, attr);
@@ -707,7 +722,7 @@ }if (strncmp (nla_data (tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME ]), -OVPN_NL_MULTICAST_GROUP_PEERS , +OVPN_MCGRP_PEERS ,nla_len (tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME ])) !=0 ) {continue ;
@@ -720,7 +735,7 @@ }/** * Lookup the multicast id for OpenVPN. This method and its help method currently -* hardcode the lookup to OVPN_NL_NAME and OVPN_NL_MULTICAST_GROUP_PEERS but +* hardcode the lookup to OVPN_FAMILY_NAME and OVPN_MCGRP_PEERS but * extended in the future if we need to lookup more than one mcast id. */ static int
@@ -741,7 +756,7 @@genlmsg_put (nl_msg,0 ,0 , ctrlid,0 ,0 ,CTRL_CMD_GETFAMILY ,0 );int ret = -EMSGSIZE ; -NLA_PUT_STRING (nl_msg,CTRL_ATTR_FAMILY_NAME ,OVPN_NL_NAME ); +NLA_PUT_STRING (nl_msg,CTRL_ATTR_FAMILY_NAME ,OVPN_FAMILY_NAME ); ret =ovpn_nl_msg_send (dco, nl_msg, mcast_family_handler, dco, __func__);
@@ -757,38 +772,38 @@dco_context_t *dco = arg;struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg)); -struct nlattr *attrs[OVPN_ATTR_MAX +1 ]; +struct nlattr *attrs[OVPN_A_MAX +1 ];struct nlmsghdr *nlh =nlmsg_hdr (msg);if (!genlmsg_valid_hdr (nlh,0 )) {msg (D_DCO ,"ovpn-dco: invalid header" ); -return NL_SKIP ; +return NL_STOP ; } -if (nla_parse (attrs,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +if (nla_parse (attrs,OVPN_A_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL )) {msg (D_DCO ,"received bogus data from ovpn-dco" ); -return NL_SKIP ; +return NL_STOP ; }/* we must know which interface this message is referring to in order to * avoid mixing messages for other instances */ -if (!attrs[OVPN_ATTR_IFINDEX ]) +if (!attrs[OVPN_A_IFINDEX ]) {msg (D_DCO ,"ovpn-dco: Received message without ifindex" ); -return NL_SKIP ; +return NL_STOP ; } -uint32_t ifindex =nla_get_u32 (attrs[OVPN_ATTR_IFINDEX ]); +uint32_t ifindex =nla_get_u32 (attrs[OVPN_A_IFINDEX ]);if (ifindex != dco->ifindex) {msg (D_DCO_DEBUG ,"ovpn-dco: ignoring message (type=%d) for foreign ifindex %d" , gnlh->cmd, ifindex); -return NL_SKIP ; +return NL_STOP ; }/* based on the message type, we parse the subobject contained in the
@@ -800,48 +815,85 @@*/ switch (gnlh->cmd) { -case OVPN_CMD_DEL_PEER : +case OVPN_CMD_PEER_DEL_NTF : { -if (!attrs[OVPN_ATTR_DEL_PEER ]) +if (!attrs[OVPN_A_PEER ]) { -msg (D_DCO ,"ovpn-dco: no attributes in OVPN_DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no peer in PEER_DEL_NTF message" ); +return NL_STOP ; } -struct nlattr *dp_attrs[OVPN_DEL_PEER_ATTR_MAX +1 ]; -if (nla_parse_nested (dp_attrs,OVPN_DEL_PEER_ATTR_MAX , - attrs[OVPN_ATTR_DEL_PEER ],NULL )) +struct nlattr *dp_attrs[OVPN_A_PEER_MAX +1 ]; +if (nla_parse_nested (dp_attrs,OVPN_A_PEER_MAX , attrs[OVPN_A_PEER ], +NULL )) { -msg (D_DCO ,"received bogus del peer packet data from ovpn-dco" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: can't parse peer in PEER_DEL_NTF messsage" ); +return NL_STOP ; } -if (!dp_attrs[OVPN_DEL_PEER_ATTR_REASON ]) +if (!dp_attrs[OVPN_A_PEER_DEL_REASON ]) { -msg (D_DCO ,"ovpn-dco: no reason in DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no reason in PEER_DEL_NTF message" ); +return NL_STOP ; } -if (!dp_attrs[OVPN_DEL_PEER_ATTR_PEER_ID ]) +if (!dp_attrs[OVPN_A_PEER_ID ]) { -msg (D_DCO ,"ovpn-dco: no peer-id in DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no peer-id in PEER_DEL_NTF message" ); +return NL_STOP ; } -int reason =nla_get_u8 (dp_attrs[OVPN_DEL_PEER_ATTR_REASON ]); -unsigned int peerid =nla_get_u32 (dp_attrs[OVPN_DEL_PEER_ATTR_PEER_ID ]); -msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_DEL_PEER, ifindex: %d, peer-id %d, reason: %d" , +int reason =nla_get_u32 (dp_attrs[OVPN_A_PEER_DEL_REASON ]); +unsigned int peerid =nla_get_u32 (dp_attrs[OVPN_A_PEER_ID ]); + +msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_PEER_DEL_NTF, ifindex: %d, peer-id %u, reason: %d" , ifindex, peerid, reason); dco->dco_message_peer_id = peerid; dco->dco_del_peer_reason = reason; - dco->dco_message_type =OVPN_CMD_DEL_PEER ; + dco->dco_message_type =OVPN_CMD_PEER_DEL_NTF ; +break ; + } +case OVPN_CMD_KEY_SWAP_NTF : + { +if (!attrs[OVPN_A_KEYCONF ]) + { +msg (D_DCO ,"ovpn-dco: no keyconf in KEY_SWAP_NTF message" ); +return NL_STOP ; + } + +struct nlattr *dp_attrs[OVPN_A_KEYCONF_MAX +1 ]; +if (nla_parse_nested (dp_attrs,OVPN_A_KEYCONF_MAX , + attrs[OVPN_A_KEYCONF ],NULL )) + { +msg (D_DCO ,"ovpn-dco: can't parse keyconf in KEY_SWAP_NTF message" ); +return NL_STOP ; + } +if (!dp_attrs[OVPN_A_KEYCONF_PEER_ID ]) + { +msg (D_DCO ,"ovpn-dco: no peer-id in KEY_SWAP_NTF message" ); +return NL_STOP ; + } +if (!dp_attrs[OVPN_A_KEYCONF_KEY_ID ]) + { +msg (D_DCO ,"ovpn-dco: no key-id in KEY_SWAP_NTF message" ); +return NL_STOP ; + } + +int key_id =nla_get_u16 (dp_attrs[OVPN_A_KEYCONF_KEY_ID ]); +unsigned int peer_id =nla_get_u32 (dp_attrs[OVPN_A_KEYCONF_PEER_ID ]); + +msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_KEY_SWAP_NTF, ifindex: %d, peer-id %u, key-id: %d" , + ifindex, peer_id, key_id); + dco->dco_message_peer_id = peer_id; + dco->dco_message_key_id = key_id; + dco->dco_message_type =OVPN_CMD_KEY_SWAP_NTF ;break ; }default :msg (D_DCO ,"ovpn-dco: received unknown command: %d" , gnlh->cmd); dco->dco_message_type =0 ; -return NL_SKIP ; +return NL_STOP ; }return NL_OK ;
@@ -859,9 +911,9 @@static void dco_update_peer_stat (struct context_2 *c2,struct nlattr *tb[],uint32_t id) { -if (tb[OVPN_GET_PEER_RESP_ATTR_LINK_RX_BYTES ]) +if (tb[OVPN_A_PEER_LINK_RX_BYTES ]) { - c2->dco_read_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_LINK_RX_BYTES ]); + c2->dco_read_bytes =nla_get_u64 (tb[OVPN_A_PEER_LINK_RX_BYTES ]);msg (D_DCO_DEBUG ,"%s / dco_read_bytes: " counter_format, __func__, c2->dco_read_bytes); }
@@ -871,9 +923,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_LINK_TX_BYTES ]) +if (tb[OVPN_A_PEER_LINK_TX_BYTES ]) { - c2->dco_write_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_LINK_TX_BYTES ]); + c2->dco_write_bytes =nla_get_u64 (tb[OVPN_A_PEER_LINK_TX_BYTES ]);msg (D_DCO_DEBUG ,"%s / dco_write_bytes: " counter_format, __func__, c2->dco_write_bytes); }
@@ -883,9 +935,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_VPN_RX_BYTES ]) +if (tb[OVPN_A_PEER_VPN_RX_BYTES ]) { - c2->tun_read_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_VPN_RX_BYTES ]); + c2->tun_read_bytes =nla_get_u64 (tb[OVPN_A_PEER_VPN_RX_BYTES ]);msg (D_DCO_DEBUG ,"%s / tun_read_bytes: " counter_format, __func__, c2->tun_read_bytes); }
@@ -895,9 +947,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_VPN_TX_BYTES ]) +if (tb[OVPN_A_PEER_VPN_TX_BYTES ]) { - c2->tun_write_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_VPN_TX_BYTES ]); + c2->tun_write_bytes =nla_get_u64 (tb[OVPN_A_PEER_VPN_TX_BYTES ]);msg (D_DCO_DEBUG ,"%s / tun_write_bytes: " counter_format, __func__, c2->tun_write_bytes); }
@@ -911,33 +963,30 @@int dco_parse_peer_multi (struct nl_msg *msg,void *arg) { -struct nlattr *tb[OVPN_ATTR_MAX +1 ]; +struct nlattr *tb[OVPN_A_MAX +1 ];struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg));msg (D_DCO_DEBUG ,"%s: parsing message..." , __func__); -nla_parse (tb,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +nla_parse (tb,OVPN_A_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL ); -if (!tb[OVPN_ATTR_GET_PEER ]) +if (!tb[OVPN_A_PEER ]) {return NL_SKIP ; } -struct nlattr *tb_peer[OVPN_GET_PEER_RESP_ATTR_MAX +1 ]; +struct nlattr *tb_peer[OVPN_A_PEER_MAX +1 ]; +nla_parse_nested (tb_peer,OVPN_A_PEER_MAX , tb[OVPN_A_PEER ],NULL ); -nla_parse (tb_peer,OVPN_GET_PEER_RESP_ATTR_MAX , -nla_data (tb[OVPN_ATTR_GET_PEER ]), -nla_len (tb[OVPN_ATTR_GET_PEER ]),NULL ); - -if (!tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]) +if (!tb_peer[OVPN_A_PEER_ID ]) {msg (M_WARN ,"%s: no peer-id provided in reply" , __func__);return NL_SKIP ; }struct multi_context *m = arg; -uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]); +uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_A_PEER_ID ]);if (peer_id >= m->max_clients || !m->instances[peer_id]) {
@@ -957,7 +1006,7 @@ {msg (D_DCO_DEBUG ,"%s" , __func__); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_GET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_GET );nlmsg_hdr (nl_msg)->nlmsg_flags |=NLM_F_DUMP ;
@@ -979,33 +1028,33 @@ dco_parse_peer(struct nl_msg *msg, void *arg) { struct context *c = arg; -struct nlattr *tb[OVPN_ATTR_MAX +1 ]; +struct nlattr *tb[OVPN_A_MAX ];struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg));msg (D_DCO_DEBUG ,"%s: parsing message..." , __func__); -nla_parse (tb,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +nla_parse (tb,OVPN_A_PEER_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL ); -if (!tb[OVPN_ATTR_GET_PEER ]) +if (!tb[OVPN_A_PEER ]) {msg (D_DCO_DEBUG ,"%s: malformed reply" , __func__);return NL_SKIP ; } -struct nlattr *tb_peer[OVPN_GET_PEER_RESP_ATTR_MAX +1 ]; +struct nlattr *tb_peer[OVPN_A_PEER_MAX +1 ]; -nla_parse (tb_peer,OVPN_GET_PEER_RESP_ATTR_MAX , -nla_data (tb[OVPN_ATTR_GET_PEER ]), -nla_len (tb[OVPN_ATTR_GET_PEER ]),NULL ); +nla_parse (tb_peer,OVPN_A_PEER , +nla_data (tb[OVPN_A_PEER ]), +nla_len (tb[OVPN_A_PEER ]),NULL ); -if (!tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]) +if (!tb_peer[OVPN_A_PEER_ID ]) {msg (M_WARN ,"%s: no peer-id provided in reply" , __func__);return NL_SKIP ; } -uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]); +uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_A_PEER_ID ]);if (c->c2.tls_multi->dco_peer_id != peer_id) {return NL_SKIP ;
@@ -1033,11 +1082,11 @@ }dco_context_t *dco = &c->c1.tuntap->dco; -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_GET_PEER ); -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_GET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_GET ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_GET_PEER_ATTR_PEER_ID , peer_id); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peer_id);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg, dco_parse_peer, c, __func__);
@@ -1071,29 +1120,7 @@const char *dco_version_string (struct gc_arena *gc) { -struct buffer out =alloc_buf_gc (256 , gc); -FILE *fp =fopen ("/sys/module/ovpn_dco_v2/version" ,"r" ); -if (!fp) - { -return "N/A" ; - } - -if (!fgets (BSTR (&out),BCAP (&out), fp)) - { -fclose (fp); -return "ERR" ; - } - -/* remove potential newline at the end of the string */ -char *str =BSTR (&out); -char *nl =strchr (str,'\n' ); -if (nl) - { - *nl ='\0' ; - } - -fclose (fp); -return BSTR (&out); +return "Unknown" ; }void
src/openvpn/dco_linux.h +19 -0
@@ -31,9 +31,27 @@#include <netlink/socket.h> #include <netlink/netlink.h> +/* Defines to avoid mismatching with other platforms */ +#define OVPN_CMD_DEL_PEER OVPN_CMD_PEER_DEL_NTF +#define OVPN_CMD_SWAP_KEYS OVPN_CMD_KEY_SWAP_NTF +typedef enum ovpn_key_slot dco_key_slot_t ;typedef enum ovpn_cipher_alg dco_cipher_t ; +/* OVPN section */ + +enum ovpn_mode { +OVPN_MODE_P2P , +OVPN_MODE_MP , +}; + +enum ovpn_ifla_attrs { +IFLA_OVPN_UNSPEC =0 , +IFLA_OVPN_MODE , + + __IFLA_OVPN_AFTER_LAST, +IFLA_OVPN_MAX = __IFLA_OVPN_AFTER_LAST -1 , +}; typedef struct {
@@ -50,6 +68,7 @@int dco_message_type;int dco_message_peer_id; +int dco_message_key_id;int dco_del_peer_reason;uint64_t dco_read_bytes;uint64_t dco_write_bytes;
src/openvpn/networking_sitnl.c +1 -1
@@ -1354,7 +1354,7 @@struct rtattr *linkinfo =SITNL_NEST (&req.n,sizeof (req),IFLA_LINKINFO );SITNL_ADDATTR (&req.n,sizeof (req),IFLA_INFO_KIND , type,strlen (type) +1 );#if defined(ENABLE_DCO ) -if (arg && (strcmp (type,"ovpn-dco" ) ==0 )) +if (arg && (strcmp (type,OVPN_FAMILY_NAME ) ==0 )) {dco_context_t *dco = arg;struct rtattr *data =SITNL_NEST (&req.n,sizeof (req),IFLA_INFO_DATA );
src/openvpn/ovpn_dco_linux.h +73 -220
329 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/941?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I009f4e7ad38636f1c0b78d267561194c2bb4c051
Gerrit-Change-Number: 941
Gerrit-PatchSet: 7
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset
[Openvpn-devel] [L] Change in openvpn[master]: dco_linux: Introduce new uAPIs
In reply to a message not in the archivecron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/941?usp=email )
Change subject: dco_linux: Introduce new uAPIs
......................................................................
dco_linux: Introduce new uAPIs
This patch updates the dco userspace API to
support communication with the new in-kernel
driver.
The main change involves updating the enums
used for Netlink messages to match the
definitions expected by the kernel module.
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg31554.html
---
M src/openvpn/dco_linux.c
M src/openvpn/dco_linux.h
M src/openvpn/networking_sitnl.c
M src/openvpn/ovpn_dco_linux.h
4 files changed, 249 insertions(+), 350 deletions(-)
src/openvpn/dco_linux.c +156 -129
@@ -96,7 +96,7 @@ }set_cloexec (nl_socket_get_fd (nl_sock)); - ret =genl_ctrl_resolve (nl_sock,OVPN_NL_NAME ); + ret =genl_ctrl_resolve (nl_sock,OVPN_FAMILY_NAME );if (ret <0 ) { msg(msglevel, "Cannot find ovpn_dco netlink component: %s",
@@ -109,7 +109,7 @@ }static struct nl_msg * -ovpn_dco_nlmsg_create (dco_context_t *dco,enum ovpn_nl_commands cmd) +ovpn_dco_nlmsg_create (dco_context_t *dco,int cmd) {struct nl_msg *nl_msg =nlmsg_alloc ();if (!nl_msg)
@@ -119,7 +119,7 @@ }genlmsg_put (nl_msg,0 ,0 , dco->ovpn_dco_id,0 ,0 , cmd,0 ); -NLA_PUT_U32 (nl_msg,OVPN_ATTR_IFINDEX , dco->ifindex); +NLA_PUT_U32 (nl_msg,OVPN_A_IFINDEX , dco->ifindex);return nl_msg; nla_put_failure:
@@ -231,20 +231,31 @@msg (D_DCO_DEBUG ,"%s: peer-id %d, fd %d, remote addr: %s" , __func__, peerid, sd, remotestr); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_NEW_PEER ); -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_NEW_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_NEW ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_PEER_ID , peerid); -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_SOCKET , sd); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_SOCKET , sd);/* Set the remote endpoint if defined (for UDP) */ if (remoteaddr) { remoteaddr =mapped_v4_to_v6 (remoteaddr, &gc); -int alen =af_addr_size (remoteaddr->sa_family); -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_SOCKADDR_REMOTE , alen, remoteaddr); +if (remoteaddr->sa_family ==AF_INET ) + { +NLA_PUT (nl_msg,OVPN_A_PEER_REMOTE_IPV4 ,sizeof (struct in_addr ), + &((struct sockaddr_in *)remoteaddr)->sin_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_REMOTE_PORT , ((struct sockaddr_in *)remoteaddr)->sin_port); + } +else if (remoteaddr->sa_family ==AF_INET6 ) + { +NLA_PUT (nl_msg,OVPN_A_PEER_REMOTE_IPV6 ,sizeof (struct in6_addr ), + &((struct sockaddr_in6 *)remoteaddr)->sin6_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_REMOTE_PORT , ((struct sockaddr_in6 *)remoteaddr)->sin6_port); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_REMOTE_IPV6_SCOPE_ID , ((struct sockaddr_in6 *)remoteaddr)->sin6_scope_id); + } }if (localaddr)
@@ -252,24 +263,26 @@ localaddr =mapped_v4_to_v6 (localaddr, &gc);if (localaddr->sa_family ==AF_INET ) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_LOCAL_IP ,sizeof (struct in_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_LOCAL_IPV4 ,sizeof (struct in_addr ), &((struct sockaddr_in *)localaddr)->sin_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_LOCAL_PORT , ((struct sockaddr_in *)localaddr)->sin_port); }else if (localaddr->sa_family ==AF_INET6 ) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_LOCAL_IP ,sizeof (struct in6_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_LOCAL_IPV6 ,sizeof (struct in6_addr ), &((struct sockaddr_in6 *)localaddr)->sin6_addr); +NLA_PUT_U16 (nl_msg,OVPN_A_PEER_LOCAL_PORT , ((struct sockaddr_in6 *)localaddr)->sin6_port); } }/* Set the primary VPN IP addresses of the peer */ if (vpn_ipv4) { -NLA_PUT_U32 (nl_msg,OVPN_NEW_PEER_ATTR_IPV4 , vpn_ipv4->s_addr); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_VPN_IPV4 , vpn_ipv4->s_addr); }if (vpn_ipv6) { -NLA_PUT (nl_msg,OVPN_NEW_PEER_ATTR_IPV6 ,sizeof (struct in6_addr ), +NLA_PUT (nl_msg,OVPN_A_PEER_VPN_IPV6 ,sizeof (struct in6_addr ), vpn_ipv6); }nla_nest_end (nl_msg, attr);
@@ -481,7 +494,7 @@msg (D_DCO_DEBUG ,"%s: %s" , __func__, dev);ASSERT (tt->type ==DEV_TYPE_TUN ); -int ret =net_iface_new (ctx, dev,"ovpn-dco" , &tt->dco); +int ret =net_iface_new (ctx, dev,OVPN_FAMILY_NAME , &tt->dco);if (ret <0 ) {msg (D_DCO_DEBUG ,"Cannot create DCO interface %s: %d" , dev, ret);
@@ -515,15 +528,15 @@ {msg (D_DCO_DEBUG ,"%s: peer-id %d" , __func__, peerid); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_SWAP_KEYS ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_SWAP );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_SWAP_KEYS ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_KEYCONF );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_SWAP_KEYS_ATTR_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -539,15 +552,15 @@ {msg (D_DCO_DEBUG ,"%s: peer-id %d" , __func__, peerid); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_DEL_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_DEL );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_DEL_PEER ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_DEL_PEER_ATTR_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -562,19 +575,19 @@ dco_del_key(dco_context_t *dco, unsigned int peerid, dco_key_slot_t slot) { +int ret = -EMSGSIZE ;msg (D_DCO_DEBUG ,"%s: peer-id %d, slot %d" , __func__, peerid, slot); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_DEL_KEY ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_DEL );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_DEL_KEY ); -int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_DEL_KEY_ATTR_PEER_ID , peerid); -NLA_PUT_U8 (nl_msg,OVPN_DEL_KEY_ATTR_KEY_SLOT , slot); -nla_nest_end (nl_msg, attr); +struct nlattr *keyconf =nla_nest_start (nl_msg,OVPN_A_KEYCONF ); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_SLOT , slot); +nla_nest_end (nl_msg, keyconf); ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -596,7 +609,7 @@const size_t key_len =cipher_kt_key_size (ciphername);const int nonce_tail_len =8 ; -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_NEW_KEY ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_KEY_NEW );if (!nl_msg) {return -ENOMEM ;
@@ -605,33 +618,35 @@dco_cipher_t dco_cipher =dco_get_cipher (ciphername);int ret = -EMSGSIZE ; -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_NEW_KEY ); -NLA_PUT_U32 (nl_msg,OVPN_NEW_KEY_ATTR_PEER_ID , peerid); -NLA_PUT_U8 (nl_msg,OVPN_NEW_KEY_ATTR_KEY_SLOT , slot); -NLA_PUT_U8 (nl_msg,OVPN_NEW_KEY_ATTR_KEY_ID , keyid); -NLA_PUT_U16 (nl_msg,OVPN_NEW_KEY_ATTR_CIPHER_ALG , dco_cipher); + +struct nlattr *key_conf =nla_nest_start (nl_msg,OVPN_A_KEYCONF ); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_SLOT , slot); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_KEY_ID , keyid); +NLA_PUT_U32 (nl_msg,OVPN_A_KEYCONF_CIPHER_ALG , dco_cipher);struct nlattr *key_enc =nla_nest_start (nl_msg, -OVPN_NEW_KEY_ATTR_ENCRYPT_KEY ); +OVPN_A_KEYCONF_ENCRYPT_DIR );if (dco_cipher !=OVPN_CIPHER_ALG_NONE ) { -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_CIPHER_KEY , key_len, encrypt_key); -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_NONCE_TAIL , nonce_tail_len, +NLA_PUT (nl_msg,OVPN_A_KEYDIR_CIPHER_KEY , key_len, encrypt_key); +NLA_PUT (nl_msg,OVPN_A_KEYDIR_NONCE_TAIL , nonce_tail_len, encrypt_iv); }nla_nest_end (nl_msg, key_enc);struct nlattr *key_dec =nla_nest_start (nl_msg, -OVPN_NEW_KEY_ATTR_DECRYPT_KEY ); +OVPN_A_KEYCONF_DECRYPT_DIR );if (dco_cipher !=OVPN_CIPHER_ALG_NONE ) { -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_CIPHER_KEY , key_len, decrypt_key); -NLA_PUT (nl_msg,OVPN_KEY_DIR_ATTR_NONCE_TAIL , nonce_tail_len, +NLA_PUT (nl_msg,OVPN_A_KEYDIR_CIPHER_KEY , key_len, decrypt_key); +NLA_PUT (nl_msg,OVPN_A_KEYDIR_NONCE_TAIL , nonce_tail_len, decrypt_iv); }nla_nest_end (nl_msg, key_dec); -nla_nest_end (nl_msg, attr); +nla_nest_end (nl_msg, key_conf); + ret =ovpn_nl_msg_send (dco, nl_msg,NULL ,NULL , __func__);
@@ -647,18 +662,18 @@msg (D_DCO_DEBUG ,"%s: peer-id %d, keepalive %d/%d, mss %d" , __func__, peerid, keepalive_interval, keepalive_timeout, mss); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_SET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_SET );if (!nl_msg) {return -ENOMEM ; } -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_SET_PEER ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_PEER_ID , peerid); -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_KEEPALIVE_INTERVAL , +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peerid); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_KEEPALIVE_INTERVAL , keepalive_interval); -NLA_PUT_U32 (nl_msg,OVPN_SET_PEER_ATTR_KEEPALIVE_TIMEOUT , +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_KEEPALIVE_TIMEOUT , keepalive_timeout);nla_nest_end (nl_msg, attr);
@@ -707,7 +722,7 @@ }if (strncmp (nla_data (tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME ]), -OVPN_NL_MULTICAST_GROUP_PEERS , +OVPN_MCGRP_PEERS ,nla_len (tb_mcgrp[CTRL_ATTR_MCAST_GRP_NAME ])) !=0 ) {continue ;
@@ -720,7 +735,7 @@ }/** * Lookup the multicast id for OpenVPN. This method and its help method currently -* hardcode the lookup to OVPN_NL_NAME and OVPN_NL_MULTICAST_GROUP_PEERS but +* hardcode the lookup to OVPN_FAMILY_NAME and OVPN_MCGRP_PEERS but * extended in the future if we need to lookup more than one mcast id. */ static int
@@ -741,7 +756,7 @@genlmsg_put (nl_msg,0 ,0 , ctrlid,0 ,0 ,CTRL_CMD_GETFAMILY ,0 );int ret = -EMSGSIZE ; -NLA_PUT_STRING (nl_msg,CTRL_ATTR_FAMILY_NAME ,OVPN_NL_NAME ); +NLA_PUT_STRING (nl_msg,CTRL_ATTR_FAMILY_NAME ,OVPN_FAMILY_NAME ); ret =ovpn_nl_msg_send (dco, nl_msg, mcast_family_handler, dco, __func__);
@@ -757,38 +772,38 @@dco_context_t *dco = arg;struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg)); -struct nlattr *attrs[OVPN_ATTR_MAX +1 ]; +struct nlattr *attrs[OVPN_A_MAX +1 ];struct nlmsghdr *nlh =nlmsg_hdr (msg);if (!genlmsg_valid_hdr (nlh,0 )) {msg (D_DCO ,"ovpn-dco: invalid header" ); -return NL_SKIP ; +return NL_STOP ; } -if (nla_parse (attrs,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +if (nla_parse (attrs,OVPN_A_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL )) {msg (D_DCO ,"received bogus data from ovpn-dco" ); -return NL_SKIP ; +return NL_STOP ; }/* we must know which interface this message is referring to in order to * avoid mixing messages for other instances */ -if (!attrs[OVPN_ATTR_IFINDEX ]) +if (!attrs[OVPN_A_IFINDEX ]) {msg (D_DCO ,"ovpn-dco: Received message without ifindex" ); -return NL_SKIP ; +return NL_STOP ; } -uint32_t ifindex =nla_get_u32 (attrs[OVPN_ATTR_IFINDEX ]); +uint32_t ifindex =nla_get_u32 (attrs[OVPN_A_IFINDEX ]);if (ifindex != dco->ifindex) {msg (D_DCO_DEBUG ,"ovpn-dco: ignoring message (type=%d) for foreign ifindex %d" , gnlh->cmd, ifindex); -return NL_SKIP ; +return NL_STOP ; }/* based on the message type, we parse the subobject contained in the
@@ -800,48 +815,85 @@*/ switch (gnlh->cmd) { -case OVPN_CMD_DEL_PEER : +case OVPN_CMD_PEER_DEL_NTF : { -if (!attrs[OVPN_ATTR_DEL_PEER ]) +if (!attrs[OVPN_A_PEER ]) { -msg (D_DCO ,"ovpn-dco: no attributes in OVPN_DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no peer in PEER_DEL_NTF message" ); +return NL_STOP ; } -struct nlattr *dp_attrs[OVPN_DEL_PEER_ATTR_MAX +1 ]; -if (nla_parse_nested (dp_attrs,OVPN_DEL_PEER_ATTR_MAX , - attrs[OVPN_ATTR_DEL_PEER ],NULL )) +struct nlattr *dp_attrs[OVPN_A_PEER_MAX +1 ]; +if (nla_parse_nested (dp_attrs,OVPN_A_PEER_MAX , attrs[OVPN_A_PEER ], +NULL )) { -msg (D_DCO ,"received bogus del peer packet data from ovpn-dco" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: can't parse peer in PEER_DEL_NTF messsage" ); +return NL_STOP ; } -if (!dp_attrs[OVPN_DEL_PEER_ATTR_REASON ]) +if (!dp_attrs[OVPN_A_PEER_DEL_REASON ]) { -msg (D_DCO ,"ovpn-dco: no reason in DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no reason in PEER_DEL_NTF message" ); +return NL_STOP ; } -if (!dp_attrs[OVPN_DEL_PEER_ATTR_PEER_ID ]) +if (!dp_attrs[OVPN_A_PEER_ID ]) { -msg (D_DCO ,"ovpn-dco: no peer-id in DEL_PEER message" ); -return NL_SKIP ; +msg (D_DCO ,"ovpn-dco: no peer-id in PEER_DEL_NTF message" ); +return NL_STOP ; } -int reason =nla_get_u8 (dp_attrs[OVPN_DEL_PEER_ATTR_REASON ]); -unsigned int peerid =nla_get_u32 (dp_attrs[OVPN_DEL_PEER_ATTR_PEER_ID ]); -msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_DEL_PEER, ifindex: %d, peer-id %d, reason: %d" , +int reason =nla_get_u32 (dp_attrs[OVPN_A_PEER_DEL_REASON ]); +unsigned int peerid =nla_get_u32 (dp_attrs[OVPN_A_PEER_ID ]); + +msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_PEER_DEL_NTF, ifindex: %d, peer-id %u, reason: %d" , ifindex, peerid, reason); dco->dco_message_peer_id = peerid; dco->dco_del_peer_reason = reason; - dco->dco_message_type =OVPN_CMD_DEL_PEER ; + dco->dco_message_type =OVPN_CMD_PEER_DEL_NTF ; +break ; + } +case OVPN_CMD_KEY_SWAP_NTF : + { +if (!attrs[OVPN_A_KEYCONF ]) + { +msg (D_DCO ,"ovpn-dco: no keyconf in KEY_SWAP_NTF message" ); +return NL_STOP ; + } + +struct nlattr *dp_attrs[OVPN_A_KEYCONF_MAX +1 ]; +if (nla_parse_nested (dp_attrs,OVPN_A_KEYCONF_MAX , + attrs[OVPN_A_KEYCONF ],NULL )) + { +msg (D_DCO ,"ovpn-dco: can't parse keyconf in KEY_SWAP_NTF message" ); +return NL_STOP ; + } +if (!dp_attrs[OVPN_A_KEYCONF_PEER_ID ]) + { +msg (D_DCO ,"ovpn-dco: no peer-id in KEY_SWAP_NTF message" ); +return NL_STOP ; + } +if (!dp_attrs[OVPN_A_KEYCONF_KEY_ID ]) + { +msg (D_DCO ,"ovpn-dco: no key-id in KEY_SWAP_NTF message" ); +return NL_STOP ; + } + +int key_id =nla_get_u16 (dp_attrs[OVPN_A_KEYCONF_KEY_ID ]); +unsigned int peer_id =nla_get_u32 (dp_attrs[OVPN_A_KEYCONF_PEER_ID ]); + +msg (D_DCO_DEBUG ,"ovpn-dco: received CMD_KEY_SWAP_NTF, ifindex: %d, peer-id %u, key-id: %d" , + ifindex, peer_id, key_id); + dco->dco_message_peer_id = peer_id; + dco->dco_message_key_id = key_id; + dco->dco_message_type =OVPN_CMD_KEY_SWAP_NTF ;break ; }default :msg (D_DCO ,"ovpn-dco: received unknown command: %d" , gnlh->cmd); dco->dco_message_type =0 ; -return NL_SKIP ; +return NL_STOP ; }return NL_OK ;
@@ -859,9 +911,9 @@static void dco_update_peer_stat (struct context_2 *c2,struct nlattr *tb[],uint32_t id) { -if (tb[OVPN_GET_PEER_RESP_ATTR_LINK_RX_BYTES ]) +if (tb[OVPN_A_PEER_LINK_RX_BYTES ]) { - c2->dco_read_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_LINK_RX_BYTES ]); + c2->dco_read_bytes =nla_get_u64 (tb[OVPN_A_PEER_LINK_RX_BYTES ]);msg (D_DCO_DEBUG ,"%s / dco_read_bytes: " counter_format, __func__, c2->dco_read_bytes); }
@@ -871,9 +923,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_LINK_TX_BYTES ]) +if (tb[OVPN_A_PEER_LINK_TX_BYTES ]) { - c2->dco_write_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_LINK_TX_BYTES ]); + c2->dco_write_bytes =nla_get_u64 (tb[OVPN_A_PEER_LINK_TX_BYTES ]);msg (D_DCO_DEBUG ,"%s / dco_write_bytes: " counter_format, __func__, c2->dco_write_bytes); }
@@ -883,9 +935,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_VPN_RX_BYTES ]) +if (tb[OVPN_A_PEER_VPN_RX_BYTES ]) { - c2->tun_read_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_VPN_RX_BYTES ]); + c2->tun_read_bytes =nla_get_u64 (tb[OVPN_A_PEER_VPN_RX_BYTES ]);msg (D_DCO_DEBUG ,"%s / tun_read_bytes: " counter_format, __func__, c2->tun_read_bytes); }
@@ -895,9 +947,9 @@ __func__, id); } -if (tb[OVPN_GET_PEER_RESP_ATTR_VPN_TX_BYTES ]) +if (tb[OVPN_A_PEER_VPN_TX_BYTES ]) { - c2->tun_write_bytes =nla_get_u64 (tb[OVPN_GET_PEER_RESP_ATTR_VPN_TX_BYTES ]); + c2->tun_write_bytes =nla_get_u64 (tb[OVPN_A_PEER_VPN_TX_BYTES ]);msg (D_DCO_DEBUG ,"%s / tun_write_bytes: " counter_format, __func__, c2->tun_write_bytes); }
@@ -911,33 +963,30 @@int dco_parse_peer_multi (struct nl_msg *msg,void *arg) { -struct nlattr *tb[OVPN_ATTR_MAX +1 ]; +struct nlattr *tb[OVPN_A_MAX +1 ];struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg));msg (D_DCO_DEBUG ,"%s: parsing message..." , __func__); -nla_parse (tb,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +nla_parse (tb,OVPN_A_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL ); -if (!tb[OVPN_ATTR_GET_PEER ]) +if (!tb[OVPN_A_PEER ]) {return NL_SKIP ; } -struct nlattr *tb_peer[OVPN_GET_PEER_RESP_ATTR_MAX +1 ]; +struct nlattr *tb_peer[OVPN_A_PEER_MAX +1 ]; +nla_parse_nested (tb_peer,OVPN_A_PEER_MAX , tb[OVPN_A_PEER ],NULL ); -nla_parse (tb_peer,OVPN_GET_PEER_RESP_ATTR_MAX , -nla_data (tb[OVPN_ATTR_GET_PEER ]), -nla_len (tb[OVPN_ATTR_GET_PEER ]),NULL ); - -if (!tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]) +if (!tb_peer[OVPN_A_PEER_ID ]) {msg (M_WARN ,"%s: no peer-id provided in reply" , __func__);return NL_SKIP ; }struct multi_context *m = arg; -uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]); +uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_A_PEER_ID ]);if (peer_id >= m->max_clients || !m->instances[peer_id]) {
@@ -957,7 +1006,7 @@ {msg (D_DCO_DEBUG ,"%s" , __func__); -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_GET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_GET );nlmsg_hdr (nl_msg)->nlmsg_flags |=NLM_F_DUMP ;
@@ -979,33 +1028,33 @@ dco_parse_peer(struct nl_msg *msg, void *arg) { struct context *c = arg; -struct nlattr *tb[OVPN_ATTR_MAX +1 ]; +struct nlattr *tb[OVPN_A_MAX ];struct genlmsghdr *gnlh =nlmsg_data (nlmsg_hdr (msg));msg (D_DCO_DEBUG ,"%s: parsing message..." , __func__); -nla_parse (tb,OVPN_ATTR_MAX ,genlmsg_attrdata (gnlh,0 ), +nla_parse (tb,OVPN_A_PEER_MAX ,genlmsg_attrdata (gnlh,0 ),genlmsg_attrlen (gnlh,0 ),NULL ); -if (!tb[OVPN_ATTR_GET_PEER ]) +if (!tb[OVPN_A_PEER ]) {msg (D_DCO_DEBUG ,"%s: malformed reply" , __func__);return NL_SKIP ; } -struct nlattr *tb_peer[OVPN_GET_PEER_RESP_ATTR_MAX +1 ]; +struct nlattr *tb_peer[OVPN_A_PEER_MAX +1 ]; -nla_parse (tb_peer,OVPN_GET_PEER_RESP_ATTR_MAX , -nla_data (tb[OVPN_ATTR_GET_PEER ]), -nla_len (tb[OVPN_ATTR_GET_PEER ]),NULL ); +nla_parse (tb_peer,OVPN_A_PEER , +nla_data (tb[OVPN_A_PEER ]), +nla_len (tb[OVPN_A_PEER ]),NULL ); -if (!tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]) +if (!tb_peer[OVPN_A_PEER_ID ]) {msg (M_WARN ,"%s: no peer-id provided in reply" , __func__);return NL_SKIP ; } -uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_GET_PEER_RESP_ATTR_PEER_ID ]); +uint32_t peer_id =nla_get_u32 (tb_peer[OVPN_A_PEER_ID ]);if (c->c2.tls_multi->dco_peer_id != peer_id) {return NL_SKIP ;
@@ -1033,11 +1082,11 @@ }dco_context_t *dco = &c->c1.tuntap->dco; -struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_GET_PEER ); -struct nlattr *attr =nla_nest_start (nl_msg,OVPN_ATTR_GET_PEER ); +struct nl_msg *nl_msg =ovpn_dco_nlmsg_create (dco,OVPN_CMD_PEER_GET ); +struct nlattr *attr =nla_nest_start (nl_msg,OVPN_A_PEER );int ret = -EMSGSIZE ; -NLA_PUT_U32 (nl_msg,OVPN_GET_PEER_ATTR_PEER_ID , peer_id); +NLA_PUT_U32 (nl_msg,OVPN_A_PEER_ID , peer_id);nla_nest_end (nl_msg, attr); ret =ovpn_nl_msg_send (dco, nl_msg, dco_parse_peer, c, __func__);
@@ -1071,29 +1120,7 @@const char *dco_version_string (struct gc_arena *gc) { -struct buffer out =alloc_buf_gc (256 , gc); -FILE *fp =fopen ("/sys/module/ovpn_dco_v2/version" ,"r" ); -if (!fp) - { -return "N/A" ; - } - -if (!fgets (BSTR (&out),BCAP (&out), fp)) - { -fclose (fp); -return "ERR" ; - } - -/* remove potential newline at the end of the string */ -char *str =BSTR (&out); -char *nl =strchr (str,'\n' ); -if (nl) - { - *nl ='\0' ; - } - -fclose (fp); -return BSTR (&out); +return "Unknown" ; }void
src/openvpn/dco_linux.h +19 -0
@@ -31,9 +31,27 @@#include <netlink/socket.h> #include <netlink/netlink.h> +/* Defines to avoid mismatching with other platforms */ +#define OVPN_CMD_DEL_PEER OVPN_CMD_PEER_DEL_NTF +#define OVPN_CMD_SWAP_KEYS OVPN_CMD_KEY_SWAP_NTF +typedef enum ovpn_key_slot dco_key_slot_t ;typedef enum ovpn_cipher_alg dco_cipher_t ; +/* OVPN section */ + +enum ovpn_mode { +OVPN_MODE_P2P , +OVPN_MODE_MP , +}; + +enum ovpn_ifla_attrs { +IFLA_OVPN_UNSPEC =0 , +IFLA_OVPN_MODE , + + __IFLA_OVPN_AFTER_LAST, +IFLA_OVPN_MAX = __IFLA_OVPN_AFTER_LAST -1 , +}; typedef struct {
@@ -50,6 +68,7 @@int dco_message_type;int dco_message_peer_id; +int dco_message_key_id;int dco_del_peer_reason;uint64_t dco_read_bytes;uint64_t dco_write_bytes;
src/openvpn/networking_sitnl.c +1 -1
@@ -1354,7 +1354,7 @@struct rtattr *linkinfo =SITNL_NEST (&req.n,sizeof (req),IFLA_LINKINFO );SITNL_ADDATTR (&req.n,sizeof (req),IFLA_INFO_KIND , type,strlen (type) +1 );#if defined(ENABLE_DCO ) -if (arg && (strcmp (type,"ovpn-dco" ) ==0 )) +if (arg && (strcmp (type,OVPN_FAMILY_NAME ) ==0 )) {dco_context_t *dco = arg;struct rtattr *data =SITNL_NEST (&req.n,sizeof (req),IFLA_INFO_DATA );
src/openvpn/ovpn_dco_linux.h +73 -220
329 lines not on this page · raw message
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/941?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I009f4e7ad38636f1c0b78d267561194c2bb4c051
Gerrit-Change-Number: 941
Gerrit-PatchSet: 7
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged